inError()

Since: Editor 1.5

Determine if there is an error condition displayed in the form.
Please note - this property requires the Editor extension for DataTables.

Description

This method can be used to determine if an error message is being shown to the end user. The form error message (error()) is always checked and the optional parameter can be used to determine what fields, if any are checked. The main form error message can be checked alone by passing in an empty array.

Please note that this method does not itself perform any validation, it just checks the form and the fields in the form to determine if any of them are in an error state.

Additionally, when Editor submits the form (i.e. submit()) it will clear any existing errors at that point. This is to allow any validation (client or server-side) to run on the freshly submitted form data. The upshot of this is that inError(), if used as the first call inside preSubmit would not show any errors, since the errors have been cleared. In this case of client-side validation, preSubmit would be expected to set the errors.

Type

inError( [ fieldNames ] )

Remove one or more fields from the form display.

Parameters:

Returns:

boolean: true if the form or a field is in the error state, otherwise false if no errors are found.

Example

Use preSubmit to cancel the form submission if any field is in an error state:

editor.on('preSubmit', function () {
	if (editor.inError()) {
		return false;
	}
});

Related

The following options are directly related and may also be useful in your application development.