user1142216
user1142216

Reputation: 39

jQueryMobile Datebox won't take a default date value - tried everything

I am trying to open a jQueryMobile datebox in a dialog mode. I am trying to set the datebox to a default value but it just won't take it for some reason. Here is my code:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" />
    <title>@PageData["Title"]</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <link rel="stylesheet" type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.min.css" /> 
    <link rel="stylesheet" href="@Href("/Styles/theme/mysite.min.css")" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
    <script src="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.min.js"></script>
    <script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/i8n/jquery.mobile.datebox.i8n.en.js"></script>
</head> 
<body> 
<script type="text/javascript">
    $('document').ready(function(){
    //Setting start date value on pageload 
    $('#myqdate').value('2012-01-14');
    $('#myqdate').datebox('refresh');
    }
</script>

<form name="shiftform" id="shiftform" action="@Href("~/Account/QChanges.cshtml")" method="post">
    <div data-role="fieldcontain">
        <label for="myqdate">Date:</label>
  <input name="myqdate" id="myqdate" type="date" value="" data-role="datebox" data-options='{"mode": "flipbox", "forceInheritTheme": true, "defaultDate":"2012-01-14"}'>
    </div>  
    <input type="submit" value="Get Queue"/>
</form>
</body>
</html>

I would really appreciate help from experts.

Thanks

Upvotes: 2

Views: 3589

Answers (3)

Daniel Araki
Daniel Araki

Reputation: 1

try closing your function: $('document').ready(function(){ //Setting start date value on pageload $('#myqdate').value('2012-01-14'); $('#myqdate').datebox('refresh'); } )};

Upvotes: 0

victorvartan
victorvartan

Reputation: 1002

It seems that you should be using the "defaultValue" property instead of the "defaultDate" that is in the data-options of your posted code. No need for the script block.

Upvotes: 0

Ion Sapoval
Ion Sapoval

Reputation: 635

This should do it:

$('#myqdate').trigger('datebox', {'method':'set', 'value':'2012-01-14', 'date':new Date('2012-01-14')})

Upvotes: 3

Related Questions