views:

25

answers:

2

I prefer my datepicker to be formatted with this option

{dateFormat: 'mm-dd-yy'}

Ex: 06-16-2010

But, I would like to allow people to enter in a slash as a seperator instead of a dash if they choose.

Is there a way to setup the datepicker so that it defaults to mm-dd-yy but wouldn't prevent someone from entering mm/dd/yy?

I do know I can set {constrainInput:false} although then people can enter letters :(

Thanks for any help.

A: 

the datepicker has the altField & altFormat option so you can show one format but send the other, but thats not what you want.

i suggest that you use datejs (http://www.datejs.com/) to parse the user input and update a hidden textbox which is linked to your datepicker.

marc.d
A: 

Absolutely. You can type anything into the field if you turn off constrainInput.

$( "#myDateInput" ).datepicker({ 
  dateFormat: 'mm-dd-yy',
  constrainInput: false
});

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

Jon Weers