I am using jQuery mobile 1.1.0. I have a form where the user can edit information. In that form are 2 fields with date values. Since I want to leverage the built in date picker functionality, the input type is set to "date". When the form loads on a desktop browser the value is set properly with a date, however when I view the same form on my mobile device (iPhone iOS 5), the date fields are not populated.
Below is one field, with the type="text". The value gets set fine:
<input type="text" id="name" />
$("#name").val(obj.Name);
The date field (type="date") never gets a value set:
<input type="date" id="startdate" />
$("#startdate").val(obj.StartDate);
As stated, on a desktop browser (Chrome/Firefox), the fields get a value set. It's on the Safari mobile that it doesn't.
If this has already been answered somewhere please excuse me! I've searched but haven't found anything related.
To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.
moment(). format('YYYY-MM-DD'); moment() returns an object representing the current date and time.
I found the answer from another post: Setting the value of date inputs on iPad
It's simply a matter of formatting the date to yyyy-MM-dd, it's that simple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With