tags:

views:

904

answers:

2

Demo: 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. Is there some reason the CSS or JS would hide it by default?

My HTML:

<input id="startDate" name="startDate" dojoType="dijit.form.DateTextBox" required=true value="08/15/2009"/>

I'm still learning to use FireBug as well. Can I find out the value by browsing the DOM?

Firebug shows:

<!-- <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>

A: 

It looks like Dijit clears out the value when the DateTextBox applies itself to the input field. I am not sure why the value attribute would not be preserved when the dijit control is bound to the input. However, the DateTextBox has a value property in the API; you could try constructing it with this value in the constructor options programmatically instead of using the dojoType attribute. 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

RMorrisey
You can also try setting dijit.byId("startDate").value, after the widget is constructed.
RMorrisey
Would I then do this to "place it" properly:dojo.byid("plannedCompletionDateWrapper").innerHTML = plannedCompletionDate I have two dates on my form, so I'm trying this technique on the second date.
NealWalters
Your syntax is resulting in this error:"_8.getMonth is not a function"I made a few slight changes: var plannedCompletionDate = new dijit.form.DateTextBox({ value: "09/02/2009" }, "plannedCompletionDate"); dojo.byid("plannedCompletionDateWrapper").innerHTML = plannedCompletionDate;
NealWalters
I would try using Firebug to see why that getMonth error is being thrown. Sorry for the mistake! The code that I wrote above doesn't call or try to call a getMonth method; but debugging into that probably will give you a lot of insight as to what is going on. I'm not sure if replacing the innerHTML is what you want to do, that seems like it might disrupt the dijit control's functionality.
RMorrisey
+3  A: 

Dojo uses ISO8601/RFC3339-style dates exclusively in markup. Any time a date value is required in markup, you should specify it exclusively as yyyy-mm-dd

<input id="startDate" name="startDate" dojoType="dijit.form.DateTextBox" required=true value="2009-08-15"/>

When setting a date attribute from JavaScript, you should use a Date object:

dojo.addOnLoad(function(){
    // make the date text box
        var startDateTextBox = new dijit.form.DateTextBox({
             value: new Date(2009, 7, 15)
        }, "startDate");
});
Right-on! Thanks. It's a little misleading because the date shows as mm/dd/yyyy, but it sort of makes sense.
NealWalters