Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get date from dijit.form.DateTextBox in given format?

Tags:

date

dojo

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?

like image 801
jslearner Avatar asked Apr 12 '11 12:04

jslearner


2 Answers

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'});
like image 165
peller Avatar answered Nov 08 '22 13:11

peller


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

like image 24
Andrei Avatar answered Nov 08 '22 11:11

Andrei