Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqueryUI datepicker and allowing non-dates?

How would I use the jqueryUI "datepicker" if I want my input field to allow non-dates (or invalid dates)?

I have a server-side script which can handle a normal date as input, or an asterisk to mean "latest date available" (amongst a few other special codes).
It would be nice to have a popup datepicker in my HTML form, but only when needed.
How can I use the jqueryUI datepicker to choose a specific date (for example, by clicking on a datepicker icon), while also allowing the user to enter one of our special codes as a "fake date"?

Thanks!

like image 272
Josh Avatar asked Feb 23 '23 19:02

Josh


1 Answers

You can use the constrainInput option to allow all characters to be entered into the input:

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

See this working example. The first input will allow any characters to be typed. The second input will only allow the defaults allowed by the datepicker widget (which I think is just numbers and the / character).

like image 109
James Allardice Avatar answered Mar 02 '23 17:03

James Allardice