error()

Since: Editor 1.0

Show / hide error messages for the whole form, or a specific field.
Please note - this property requires the Editor extension for DataTables.

Description

It can often be useful to show an error message informing the end user that they need to take action on a specific field, or if a global form error has occurred. Common use cases are individual and multiple field validation and general error reporting, such as a database communications error.

This method provides the ability to set a global form error message, an error message for a specific field, or to remove any existing error messages.

Note that the field().error() method introduced in Editor 1.3 provides the same functionality as the second form of this method. Both forms will continue to be supported in future versions of Editor, and they can often be used interchangeably. The key difference is in the return value - this method will return a DataTable.Editor instance, while the field().error() method returns a DataTable.Editor.Field instance. This can effect how you chain methods if you are using the returned value for chaining.

Types

error( msg )

Show or hide a global form error message

Parameters:

Returns:

DataTable.Editor: Editor instance

error( fieldName, msg )

Show or hide an error message for a specific field.

Parameters:

Returns:

DataTable.Editor: Editor instance

Examples

Show a form error for a short amount of time and then remove:

editor.error('An error has occurred');

setTimeout(function () {
	editor.error('');
}, 5000);

Client-side validation using the preSubmit event and showing an error message.:

editor.on('preSubmit', function (e, d) {
	if (this.val('username') === '') {
		this.error('username', 'A user name is required');
		return false;
	}

	return true;
});

Related

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