Having an issue on a form validating the start and end dates.
The dates are two separate fields but the values need to be compared when one is changed and error if the start date begins after the end date.
I've created a listener against each field but it appears to validate both fields even though only one has been changed.
This is resulting in the first field getting reset and therefore I have to error both fields in each validation procedure.
I expected when an error was found that its immediately returned to the form and displays, but I may not be controlling the form correctly.
main.js file
'maintenanceform #PRAS051': {
change: this.goValidateAllocationPRAS051
},
'maintenanceform #PRAE051': {
change: this.goValidateAllocationPRAE051
},
goValidateAllocationPRAE051: function(field, record) {
// Use new field value for validation;
endDate = record;
// Retrieve original value;
startDate = this.getMaintenanceForm().getForm().getRecord().da ta.PRAS051;
// If fields not yet populated or just cleared then exit;
if (startDate === 0 && endDate === 0) {
return;
}
// Check whether or not date meets correct criteria;
if (startDate > endDate) {
// Mark the relevant field incorrect;
if (field.name === 'PRAE051') {
this.getMaintenanceForm().down('#PRAE051').markInv alid('End Date begins before Start Date');
this.getMaintenanceForm().down('#PRAS051').markInv alid('Start Date begins after End Date');
this.getMaintenanceForm().getForm().getRecord().is Valid().PRAE051 = false;
this.getMaintenanceForm().getForm().getRecord().is Valid().PRAS051 = false;
}
return 0;
} else {
this.getMaintenanceForm().getForm().getRecord().is Valid().PRAE051 = true;
}
},
If the fields are corrected and the form is reset the error appears to hang around, initially errors on a new record until you click into the field.
The dates are two separate fields but the values need to be compared when one is changed and error if the start date begins after the end date.
I've created a listener against each field but it appears to validate both fields even though only one has been changed.
This is resulting in the first field getting reset and therefore I have to error both fields in each validation procedure.
I expected when an error was found that its immediately returned to the form and displays, but I may not be controlling the form correctly.
main.js file
'maintenanceform #PRAS051': {
change: this.goValidateAllocationPRAS051
},
'maintenanceform #PRAE051': {
change: this.goValidateAllocationPRAE051
},
goValidateAllocationPRAE051: function(field, record) {
// Use new field value for validation;
endDate = record;
// Retrieve original value;
startDate = this.getMaintenanceForm().getForm().getRecord().da ta.PRAS051;
// If fields not yet populated or just cleared then exit;
if (startDate === 0 && endDate === 0) {
return;
}
// Check whether or not date meets correct criteria;
if (startDate > endDate) {
// Mark the relevant field incorrect;
if (field.name === 'PRAE051') {
this.getMaintenanceForm().down('#PRAE051').markInv alid('End Date begins before Start Date');
this.getMaintenanceForm().down('#PRAS051').markInv alid('Start Date begins after End Date');
this.getMaintenanceForm().getForm().getRecord().is Valid().PRAE051 = false;
this.getMaintenanceForm().getForm().getRecord().is Valid().PRAS051 = false;
}
return 0;
} else {
this.getMaintenanceForm().getForm().getRecord().is Valid().PRAE051 = true;
}
},
If the fields are corrected and the form is reset the error appears to hang around, initially errors on a new record until you click into the field.
Comment