field().inError()
Since: Editor 1.3
Check if a field is currently in an error state.
Please note - this property requires the Editor extension for DataTables.
Description
This method provides the ability to check if a field is in an error state or not. A field is defined to be in an error state if an error message is shown (using error() or field().error()) and not in error if no error message is shown.
Type
field(…).inError()
Check if the field is in an error state or not.
Returns:
boolean: true if the field is currently in an error state (i.e. an error message is shown), or false if not in error (i.e. no error message shown).
Example
Update an error message on each keypress for a field and check the error state on form submit:
// Key press handler to update an error message on each key stroke
$('input', editor.field('password').node()).on('keypress', function () {
editor
.field('password')
.error(this.length < 8 ? 'Password must be at least 8 characters.' : '');
});
editor.on('preSubmit', function () {
// Check the error state of the field. Note we could also check the data value
if (editor.field('password').inError()) {
editor.field('password').focus();
return false; // prevent the submission
}
});Related
The following options are directly related and may also be useful in your application development.