简体   繁体   中英

How to enable the input that was attached by datePicker ui?(JQuery plugin)

$('#date_arrow_from, #date_from').click(function() {

        $('#date_from').attachDatepicker({
            rangeSelect: false,
            yearRange: "2011:2012",
            firstDay: 1
        });

        $('#date_from').showDatepicker();

    });

http://jqueryui.com/demos/datepicker/ - I am using something like this, but the problem is that when I click on the input I can't write anything, the keypress event is blocked, how can I unlock the input to be enabled?

Looks like you need to set constrainInput option to false

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

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

Code examples initialize a datepicker with the constrainInput option specified.

$(".selector" ).datepicker({ constrainInput: false });

Edit

While the above was marked as accepted I agree with @Edd Morgan that you should try and take advantage of the built in input validation (I always do when I'm using it). To specifically allow dates in the ISO 8601 format you can change the datepickers dateFormat string very easily and the demo below has a good list of examples.

http://jqueryui.com/demos/datepicker/#date-formats

$(".selector" ).datepicker({ dateFormat: "yy-mm-dd" });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM