How to make jqueryUI datepicker submit in a different format than what is being displayed?

Wally Lawless picture Wally Lawless · Jul 17, 2012 · Viewed 43.7k times · Source

I'm working on some internationalization using jQueryUI. I have a DatePicker control on a form that is properly working in the French language.

When I select a date, for example August 15, 2012, the DatePicker will display 15 Aoû, 2012 as I would expect. My issue however, is that when the form is posted, the value of the DatePicker is posted as '15 Aoû, 2012' which now needs to be translated on the server before it can be saved properly.

My question is, is there a built-in way inside the jQueryUI DatePicker so that I can have it always post to the server in a consistent format, regardless of which language the control is being displayed in? If there isn't a built-in way, what options exist for achieving this?

I realize that I can change the dateformat to something like 08/15/2012 instead of using the textual representation, however this isn't what I want to do.

Answer

iwiznia picture iwiznia · Dec 19, 2012

There's 2 configuration options for that: altField and altFormat. http://api.jqueryui.com/datepicker/#option-altField If you specify an altField, that field will be updated too, and will have the altFormat. Normally you will want make the altField a hidden field, soyou can ignore the regular field and send to db the altField.