Reputation: 13
We are using dojo DateTextbox in our applications. Earlier it was displaying local format mm/dd/yyyy
Now end user needs same in dd-MMM-yyyy format. Below code will take care for single textbox.
<input id="startDate" name="startDate" size="10" value="${fromdate }"
dojoType="dijit.form.DateTextBox" required="true"
constraints="{min:'08/22/2008',datePattern : 'dd-MMM-yyyy'}" />
But we have many DateTextBoxs in our project. Adding constraints attribute in all the textfield would be tedious job.
Is there any we can define it globally so it would take care of all the textfields ?
thanks
Upvotes: 1
Views: 3247
Reputation: 44665
The proper way to do that is to extend from the DateTextBox
and define your constraints.
For example:
declare("CustomDateTextBox", [DateTextBox], {
postCreate: function() {
this.inherited(arguments);
this.set('constraints', {
min: '08/22/2008',
max: new Date(),
datePattern: 'dd-MMM-yyyy'
});
}
});
This ofcourse means that you need to use CustomDateTextBox
in stead of DateTextBox
. If you really want to use the dijit/form/DateTextBox
you can define the name dijit/form/DateTextBox
but I don't recommend it because if you would ever need the default DateTextBox
too, you can't.
The this.inherited(arguments)
is also very important since it will run a super-call, this means that the default postCreate
will also be called (without it your widget won't work).
I also made a full example at JSFiddle, if you want to use dijit/form/DateTextBox
you can use this example.
EDIT: I just noticed you're using Dojo 1.6. The code won't work but the idea is the same, just extend your widget and it will work.
EDIT 2: This code might work with Dojo 1.6.
Upvotes: 2
Reputation: 5041
A couple of alternatives are
An example is:
var myConstraints = {
min: new Date( 1950, 2, 10),
max: new Date(),
datePattern : 'dd-MMM-yyyy'
};
Then when you declare a box have:
constraints: myConstraints
Upvotes: 0