emil.c
emil.c

Reputation: 2018

Is there an option that sets the default date when you open up datebox jquerymobile

I think the question pretty explains what I want to achieve. I've got this code:

<input type="date" data-role="datebox" data-options='{"mode": "datebox","noButton": true,"useDialogForceTrue": true, "useDialogForceFalse": false}' name="mydate" id="mydate" />

And I want to set some default date when user opens up the datebox window in the input data-options so it won't take another line of code.

Thanks.

Upvotes: 1

Views: 1716

Answers (1)

Jasper
Jasper

Reputation: 76003

HTML

<label for="mydate">Some Date</label>

<input name="mydate" id="mydate" type="date" data-role="datebox"
   data-options='{"mode": "calbox"}'>

<a href="#" id="linkmodelink">Open Link</a>

jQuery

$('#thisPageID').live('pagecreate', function(event) {
  // Default picker value of Jan 1, 2012
  var defaultPickerValue = [2012, 0, 1];

  // Make it a date
  var presetDate = new Date(defaultPickerValue[0], defaultPickerValue[1], defaultPickerValue[2], 0, 0, 0, 0);

  // Get Today
  var todaysDate = new Date(); 

  // Length of 1 Day
  var lengthOfDay = 24 * 60 * 60 * 1000; 

  // Get the difference
  var diff = parseInt((((presetDate.getTime() - todaysDate.getTime()) / lengthOfDay)+1)*-1,10); 

  // Set the origin date
  $('#mydate').data('datebox').options.defaultPickerValue = defaultPickerValue;

  // Set minDays to disallow anything earlier
  $('#mydate').data('datebox').options.minDays = diff; 
});

Source: http://dev.jtsage.com/jQM-DateBox/demos/script/start.html

Upvotes: 1

Related Questions