4

Is there a way to display a date in an input different from the format I want to submit.

For example I have to submit a date in "yyyy-mm-dd" format but I want to display the date in another format : "dd/mm/yyyy" (french display). Is there a good tip to do that with Datebox for jQuery Mobile (an option I didn't see ?)

I think I have to cheat in creating an input hidden with the good form format and another one with the format to display (and not submitted), but maybe a better solution exists.

Any ideas ?

Charlyecho
  • 41
  • 1
  • 2

3 Answers3

3

Your best bet is to indeed use 2 inputs - but, it's pretty easy to do, and using a callback on the set event, you can even make datebox do the second format for you.

http://dev.jtsage.com/jQM-DateBox2/demos/script/split.html

(Note: I just added the demo, so you didn't miss it earlier)

J.T.Sage
  • 1,984
  • 14
  • 21
2

Just a small addition

It should be "overrideDateFormat":"%d/%m/%Y" in the HTML inline options.

In http://dev.jtsage.com/jQM-DateBox2/demos/script/split.html it states "dateFormatOverride":"%d/%m/%Y"} however this is incorrect and doesn't work. Just a heads up for anyone else with this issue.

Zaylril
  • 111
  • 2
  • 5
1

Yes you need to use this method.

   <!-- fix american date formatting -->
   <script type="text/javascript">
   jQuery.extend(jQuery.mobile.datebox.prototype.options, {
       'overrideDateFormat': '%d/%m/%Y',
       'overrideHeaderFormat': '%d/%m/%Y'
   });
   </script>
Matthew Fedak
  • 772
  • 9
  • 16