Dear All
I need to validate the “NOT REQUIRED DATE FIELD” for the correct input format. If the user enters letters or a date in the date field in the wrong format, the user should get an error asking them to use a selection from the calendar. But also the user should be able to leave the field blank. I have tried the following options but it doesn't work for an empty field, I can't leave the field blank.
There is no problem with checking the input format, there is a problem with leaving the field blank.
Example 1
fd.field('CustomerContractDate').validators.push({
name: 'MyCustomValidator',
error: '!!!!!!!!',
validate: function(value) {
if (fd.field('CustomerContractDate').value == null && fd.validators.length == 0) {
this.error = 'Use the selection or enter manually (dd.mm.yyyy)';
return false;
}
return true;
}
});
Example 2
fd.field('WarrantyStart').addValidator({
name: 'WarrantyStart validator',
error: 'Warranty From is in incorrect format. Please, use DatePicker',
validate: function(value) {
return !isNaN(Date.parse(value));
}
});
Example 3
fd.field('DatePickerField').addValidator({
name: 'DatePickerValidator',
error: "Please use the date picker to select a date.",
validate: function(value) {
if (!value) {
return false;
}
return true;
}
});
Example 4
// Set the date format to 'dd.MM.yyyy'
datePickerField.dateFormat = 'dd.MM.yyyy';
fd.field('CustomerContractDate').validators.push({
name: 'DatePickerValidator',
error: "Please use the date picker to select a date.",
validate: function() {
// Check if the value was manually entered (not selected from the date picker)
if (CustomerContractDate.value && !CustomerContractDate.control().isDateSelected())
{
return true;
}
return false;
}
});