Reputation: 4622
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!
Upvotes: 4
Views: 4392
Reputation: 165971
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).
Upvotes: 8
Reputation: 794
Seems to my recollection that when I've used jQueryUI datepicker the datepicker fills in the value into a text field, but the user can still just close out the picker and type into the text field directly. Give it a try?
Upvotes: 0