开发者

JQuery DatePicker constrainInput: true not working like I think it should

开发者 https://www.devze.com 2023-03-27 09:09 出处:网络
It is only allowing numbers in the boxif you type \"22\" you cannot type a space or any characthers. How do I fix this

It is only allowing numbers in the box if you type "22" you cannot type a space or any characthers.

How do I fix this

<SCRIPT>
    $(function()开发者_如何学运维 {
        $( "#dateExpire" ).datepicker({ 
        constrainInput: true,
        changeYear:true, 
        altField: 'input#dateExpire', 
        altFormat: 'dd M yy',
        minDate: new Date(2011, 8,9</cfoutput>)
        });
    });
</SCRIPT>


You fix it by applying the format you want to the dateFormat option:

dateFormat: 'dd M yy'

constrainInput: http://jqueryui.com/demos/datepicker/#option-constrainInput

When true entry in the input field is constrained to those characters allowed by the current dateFormat.

dateFormat: http://jqueryui.com/demos/datepicker/#option-dateFormat


Another solutions is you don't use 'constrainInput' at all.

What you can is bind an 'keyup' event listener on the date_picker field and set the value

to empty. i.e. date_picker field would have a valid value if it is selected from the date

picker otherwise it would remain empty.

$("#date_picker_id")

.datepicker()

.on('keyup', function () {

                $(this).val('');

            });
0

精彩评论

暂无评论...
验证码 换一张
取 消