How to get date with dijit.form.DateTextBox in this format?

I have a dojo text box in an html file. Now I want to get the date from the text box in the format of the string "yyyy-mm-dd". How can i do this?

dojoType="dijit.form.DateTextBox" 

How can i do this?

+6
source share
3 answers

Assuming you have a widget link to your DateTextBox using something like dijit.byId(...) or dijit.byNode(dojo.query(...)) , this will get a Javascript Date object and format it in according to ISO 8601 (yyyy-mm-dd), an independent display or locale with which you may be using

  dojo.require('dojo.date.stamp'); ... var dateObject = widget.get('value'); var isoFormat = dojo.date.stamp.toISOString(dateObject, {selector: 'date'}); 
+7
source

try the following: HTML:

 <input type="text" name="date1" id="date1" value="2005-12-30" dojotype="dijit.form.DateTextBox" required="true" /> 

To get the displayed value, you can use this text field of the date method:

 // get widget: var dtb = dijit.byId('date1'); // get value alert(dtb.get('displayedValue')); 

Note *

Dojo format the date according to the user's language.

IF you can use a format that is different from the user's locale format for which you want to specify a restriction property for a date text field.

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

+4
source

This is an old question, but you can just use the toString method widget.

 var isoString = dijit.byId(widgetId).toString(); 
0
source

Source: https://habr.com/ru/post/885725/


All Articles