Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to specify the display format for a dijit.form.DateTextBox

Tags:

date

dojo

Is it possible to specify the display format for a dijit.form.DateTextBox?

I know that dijit.form.DateTextBox gets its date format from the user's locale by default and I know I can swtich the locale to anything I want, but I need to just specify the date format and not change anything else. Is this possible?

Thanks.

like image 885
Kyle Boon Avatar asked May 05 '11 21:05

Kyle Boon


1 Answers

Yes, you can do something like this:

var occursOnField = new dijit.form.DateTextBox({
    constraints: { datePattern : 'yyyy-MM-dd' }
    , promptMessage: "yyyy-MM-dd"
    , invalidMessage: "Invalid date format. Use yyyy-MM-dd"
})

Update Jan 29, 2012:

Chrome and Dojo 1.6.1 compatibility bug.

If the day of month is being padded with too many 0s, use one less d in the date pattern to work around the bug. For example, on Google Chrome 16 and Dojo 1.6.1 : datePattern : 'yyyy-MM-dd' will give 2010-01-001 and datePattern : 'yyyy-MM-d' will give 2010-01-1.

like image 101
Richard Ayotte Avatar answered Nov 23 '22 00:11

Richard Ayotte