I have a dojo text box in a html file.Now i want to retrieve the date from text box in a string format 'yyyy-mm-dd'. How can i do it?
dojoType="dijit.form.DateTextBox"
How can I do it?
Assuming you have a reference widget
to your DateTextBox widget using something like dijit.byId(...)
or dijit.byNode(dojo.query(...))
, this will get the Javascript Date object and format it according to ISO 8601 standard (yyyy-mm-dd), independent of the display or the locale you happen to be using
dojo.require('dojo.date.stamp');
...
var dateObject = widget.get('value');
var isoFormat = dojo.date.stamp.toISOString(dateObject, {selector: 'date'});
try this: HTML:
<input type="text" name="date1" id="date1" value="2005-12-30"
dojotype="dijit.form.DateTextBox" required="true" />
To get displayed value you can use this method of date text box:
// get widget:
var dtb = dijit.byId('date1');
// get value
alert(dtb.get('displayedValue'));
NOTE*:
Dojo format the date according user locale.
IF you can use format which differs with user locale format you need specify constraint property for date text box.
<input type="text" name="date1" id="date1" value="2005-12-30"
constraints="{datePattern:'yyyy-MM-dd', strict:true}"
dojotype="dijit.form.DateTextBox" required="true" />
HTML Page - example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With