Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 610
Wally Lawless Avatar asked Jul 17 '12 12:07

Wally Lawless


People also ask

How do I change the datepicker format?

The solution is to use the date picker dateFormat option. ..and use the following code to change the format with the dateFormat option. We have set it to 'dd-mm-yy'. View the file in a browser and select a date.

How do I change datepicker format from DD MM to YYYY?

var year = 2014; var month = 5; var day = 10; var realDate = new Date(year, month - 1, day); // months are 0-based! $('#MainContent_txtDataConsegna'). datepicker({ dateFormat: 'dd/mm/yyyy' }); // format to show $('#MainContent_txtDataConsegna'). datepicker('setDate', realDate);

How do I change date format in kendo datepicker?

You can control the format of the DatePicker by using the format property. The component can be configured either to display a single format at all times, or to display the value in different formats when the input is focused or blurred.


1 Answers

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.

like image 117
iwiznia Avatar answered Oct 07 '22 07:10

iwiznia