field().get()

Since: Editor 1.3

Get the value of a field.
Please note - this property requires the Editor extension for DataTables.

Description

It is often useful to be able to get the value of a field, for example in client-side validation, or data manipulation. This method provides that ability for individual fields.

When used while multi-row editing, this method has the following behaviour:

  • If all items being edited have the same value for this field, that value is returned
  • If the items being edited have different values for this field, undefined is returned. field().multiGet() should be used to access individual values if this is the case.

In addition to this method, Editor provides a number of other methods that can be used to get and set field values - each with their own speciality. Please refer to the Related selection below for links to these methods.

Type

field(…).get()

Get the current value of a field.

Returns:

Any: The value of the field or undefined if multi-row editing and the items being edited have different values for this field.

Examples

Client-side validation using preSubmit:

editor.on('preSubmit', function (e, d) {
	var usernameField = this.field('username');

	if (usernameField.get() === '') {
		usernameField.error('A user name is required');
		return false;
	}

	return true;
});

Check a value from a row being edited and submit immediately if certain data is found.:

$('#myTable tbody').on('click', 'tr', function () {
	editor.edit(this, false);

	if (editor.field('access').get() === 'all') {
		editor.field('admin').set(1);
		editor.submit();
	}
});

Related

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