I'm using mobiscroll date scroller in an app. I have it set up to initialize to a date I get from the database and set as the value of my input field. Here is my code:
$(function(){
$("#requestDate").scroller({
preset: 'date',
theme: 'jqm',
display: 'modal',
mode: 'scroller',
dateOrder: 'mdyyyy',
dateFormat: 'm/d/yyyy'
});
var requestDate = $("#requestDate").val();
if(requestDate != ""){
requestDate = new Date(requestDate);
$("#requestDate").scroller('setDate', requestDate, true);
}
});
Here is my form field:
<input type="text" name="requestDate" id="requestDate" data-role="mobiscroll" value="2013,7,25" data-mini="true" readonly="" class="ui-input-text ui-body-f ui-corner-all ui-shadow-inset ui-mini">
This shows the date formatted in the text input and defaults to that date when mobiscroll is opened. Except for in Safari. In safari the date shows as NaN/NaN/NaN. How do I fix this? Thanks!
You don't need to call setDate
, just put the date in the correct format as the input value.
See example: http://jsfiddle.net/RQzbw/
Note 1: Use 'mdyy'
and 'm/d/yy'
, yyyy
is incorrect (see documentation)
Note 2: .scroller()
is deprecated, use .mobiscroll()
instead. If you are using an older version, you should upgrade to latest.