简体   繁体   English

Dojo / Dijit-DateTextBox隐藏我的初始值

[英]Dojo/Dijit - DateTextBox hides my initial value

Demo: http://3wcloud-com-provisioning-qa.appspot.com/testDijitDate 演示:http: //3wcloud-com-provisioning-qa.appspot.com/testDijitDate

The calendar pop-up works fine and lets me pick a new date. 日历弹出窗口工作正常,我可以选择一个新日期。 But when the page loads, I see the date 08/15/2009 flash for just a moment, then it disappears. 但是,当页面加载时,我看到日期08/15/2009闪烁了片刻,然后消失了。 Is there some reason the CSS or JS would hide it by default? CSS或JS默认将其隐藏是出于某种原因吗?

 dojo.require("dijit.form.DateTextBox"); 
 <link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/resources/dojo.css" rel="stylesheet" /> <link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dijit/themes/claro/claro.css" rel="stylesheet" /> <script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js" djConfig="parseOnLoad:true"></script> <body class="claro"> <input id="startDate" name="startDate" dojoType="dijit.form.DateTextBox" required=true value="08/15/2009" /> 

I'm still learning to use FireBug as well. 我仍在学习使用FireBug。 Can I find out the value by browsing the DOM? 我可以通过浏览DOM找出价值吗?

Firebug shows: Firebug显示:

 <!-- <input type=text name=startDate size=10 value=""> --> <div wairole="presentation" dojoattachevent="onmouseenter:_onMouse,onmouseleave:_onMouse,onmousedown:_onMouse" id="widget_startDate" class="dijit dijitReset dijitInlineTable dijitLeft dijitTextBox dijitDateTextBox" role="presentation" widgetid="startDate"> <div style="overflow: hidden;"> <div class="dijitReset dijitValidationIcon"> <br/> </div> <div class="dijitReset dijitValidationIconText">Χ</div> <div class="dijitReset dijitInputField"> <input type="text" autocomplete="off" dojoattachpoint="textbox,focusNode" class="dijitReset" aria-valuenow="" aria-invalid="true" id="startDate" tabindex="0" aria-required="true" value="" /> <input type="text" style="display: none;" name="startDate" /> </div> </div> </div> 

Dojo uses ISO8601/RFC3339-style dates exclusively in markup. Dojo仅在标记中使用ISO8601 / RFC3339样式的日期。 Any time a date value is required in markup, you should specify it exclusively as yyyy-mm-dd When setting a date attribute from JavaScript, you should use a Date object: 任何时候在标记中需要日期值时,都应将其专门指定为yyyy-mm-dd从JavaScript设置日期属性时,应使用Date对象:

 dojo.require("dijit.form.DateTextBox"); dojo.addOnLoad(function() { // make the date text box var startDateTextBox = new dijit.form.DateTextBox({ value: new Date(2009, 7, 15) }, "startDate"); }); 
 <link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/resources/dojo.css" rel="stylesheet" /> <link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dijit/themes/claro/claro.css" rel="stylesheet" /> <script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js" djConfig="parseOnLoad:true"></script> <body class="claro"> <input id="startDate" name="startDate" dojoType="dijit.form.DateTextBox" required=true value="2009-08-15" /> 

It looks like Dijit clears out the value when the DateTextBox applies itself to the input field. 当DateTextBox将其自身应用于输入字段时,Dijit似乎清除了该值。 I am not sure why the value attribute would not be preserved when the dijit control is bound to the input. 我不确定将dijit控件绑定到输入时为什么不保留value属性。 However, the DateTextBox has a value property in the API; 但是,DateTextBox在API中具有value属性。 you could try constructing it with this value in the constructor options programmatically instead of using the dojoType attribute. 您可以尝试以编程方式在构造函数选项中使用此值构造它,而不是使用dojoType属性。 I think it would look something like: 我认为它看起来像:

dojo.addOnLoad(function(){
    // make the date text box
        var startDateTextBox = new dijit.form.DateTextBox({
             value: "08/15/2009"
        }, "startDate");
});

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM