views:

27

answers:

1

I have an input field that is being set as a date picker. When I initialize the dateFormat option it stops constraining the input and I can enter all sorts of rubbish dates in the text box. Why does this happen? I'd like to have constrained input still work when setting a custom date format.

myTextInput.datepicker({ dateFormat: "dd-M-yy" });

If I don't set the dateFormat option then the input is constrained as expected.

+1  A: 

It doesn't appear to be the custom date format itself that is breaking it. It appears that when your dateFormat includes a string representation that it isn't restricting.

$('#mydate').datepicker({ dateFormat: "yy-mm-dd" });

This seems to work correctly.

So basically the codes M, MM, D and DD break it.

MacAnthony
Ah ok, I get what you mean. So because the format I'm using allows dates like 12-JUL-2010, it will basically disable the constraints and allow any text. I thought it would've been smarter and only allowed the characters in JAN, FEB, MAR, etc. Any idea how to easily restrict the text entered in with jQuery?
GiddyUpHorsey
The documentation makes it sound like it should be smarter as well. You could make your own constraint on the field to only allow numbers and alpha characters. A solution for that is here (just ignore the preview stuff) http://stackoverflow.com/questions/1397535/block-characters-from-input-text-field-mirror-input-into-span-or-div
MacAnthony