Search code examples
javascriptdojodijit.form

set dijit/form/TimeTextbox programmatically


I'm not able to set the value of a dijit/form/TimeTextbox with a date returned from my database or with just a string -- I'm using dojo version 1.10.4

widget:

    <input type="text" 
    data-dojo-type="dijit/form/TimeTextBox"
    data-dojo-attach-point="tbMtgTime"
    value="T15:00:00"

trying string:

this.tbMtgTime.set("value", "10:30 AM");//doesnt work

trying value from sqlserver database:

var mtgDate = new Date(parseInt(MI.OnSiteMeetingDateInt) * 1000);
                mtgDate.setTime(mtgDate.getTime() + mtgDate.getTimezoneOffset() * 60 * 1000);
                this.tbMtgDate.set("value", mtgDate);
                var mtgTime = ddl.format(mtgDate, {
                    selector: "time",
                    timePattern: 'HH:mm a'
                });
               this.tbMtgTime.set("value", mtgDate);//mtgDate is also 10:30 AM

Thanks


Solution

  • Your string example won't work because it's not in the THH:MM format that TimeTextBox expects to handle (as opposed to the value in your declarative widget markup, which is in the correct format). The Reference Guide explains that this is the only string format that the TimeTextBox widget directly supports.

    Passing a date when setting the value programmatically is supported, and will pick up the hour and minute from the passed Date object, so ostensibly the first part of your second example should work, presuming the Date is valid. (I think the latter part of your second example intended to call set('value', mtgTime), but this won't work for the reason explained above.)