Reputation: 26464
I have a JS overlay layer which sets up data entry controls on my web app as dojo widgets. I grab inputs like <input type="text" class="date" /> and turn them into DateTextBox
widgets.
Here is my basic code:
var df = dateformat;
df.replace('mm', 'MM');
var val = input.value;
if (val == undefined){
val = '';
}
return new datebox({
"label": input.title,
"value": val,
"name": input.name,
"id": input.id,
"constraints": { "datePattern": df }
});
My problem is that all DateTextBox's end up set with '1970-00-01' as the initial date if no value is provided. I would like them to be set to null or undef if no value is provided but this doesn't seem possible until after startup.
Is there a way to set this before I call widget.startup()
?
Upvotes: 3
Views: 2854
Reputation: 7852
Instead of passing empty string to the DateTextBox you need to pass the literal null
or undefined
. I put together a jsfiddle demonstrating the different types of values and how they initially display:
require(['dijit/form/DateTextBox', 'dojo/domReady!'], function (DateTextBox) {
//initial value current date
new DateTextBox({
value: new Date()
}).placeAt('myBody');
//no value
new DateTextBox({
}).placeAt('myBody');
//null value
new DateTextBox({
value: null
}).placeAt('myBody');
//undefined value
new DateTextBox({
value: undefined
}).placeAt('myBody');
//empty string value
new DateTextBox({
value: ''
}).placeAt('myBody');
});
Upvotes: 6