Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Mobile, HTML5, setting input field of type="date"

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.

like image 930
AK76 Avatar asked Jun 20 '12 16:06

AK76


People also ask

How can set input type date in mm/dd/yyyy format using HTML?

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.

How do you display the current date in a field in HTML?

moment(). format('YYYY-MM-DD'); moment() returns an object representing the current date and time.


1 Answers

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.

like image 61
AK76 Avatar answered Sep 29 '22 08:09

AK76