Implementing Final Validation
Implementing Final Validation
To validate the complete form after the user has entered all field values you can add an event listener for the
beforeSave
event:
employeeForm_beforeSave: function() {
var employeeStandard = this.employeeForm.getFieldValue('em.em_std');
if (employeeStandard == '') {
// mark field as invalid and add a custom validation message to the field
this.employeeForm.fields.get('em.em_std').setInvalid(getMessage('error_em_std'));
return false;
}
}
The form will call your listener immediately before saving the record (regardless of how the save was initiated). To fail the validation process and prevent the form from saving, return
false
from the function. The form will display the error message dialog. The form will also highlight all fields for which your function called the
setValue(false, message)
method and display corresponding messages for each field.
canSave
The canSave() method is used by the form panel to validate field values before saving the record, typically when the user clicks on the Save button in the form. Application developers can call the canSave() method directly if they need to validate the form fields without saving the record - for example, when sending the form filed values to a custom workflow rule.
The canSave() method by default performs limited field validation in the browser. For example, if verifies that the field maximum length is not exceeded. The full validation is performed on the server when the record is saved.
Application developers may add a "beforeSaveListener" function to the form panel, which will be called by the canSave() method. This function can implement custom form field validation. The beforeSave listener function should be declared to accept one argument - the form panel object - and can return boolean "true" if the validation was successful, or boolean "false" if the validation failed.
Example of the custom form validation:
schema/ab-products/solutions/programming/form/ab-ex-prg-form-validation.axvw
schema/ab-products/solutions/programming/form/ab-ex-prg-form-validation.js