fields.compare

Since: Editor 1.7

Define a custom comparison function for the field's data.
Please note - this property requires the Editor extension for DataTables.

Description

Editor has the ability to determine if a field's data should be submitted to the server or not based on the submit option of the form-options object for the form. This can be useful to restrict submission of data to only those items which have changed value.

This property provides the ability to tell Editor how to determine if a field has changed value or not. By default Editor will use a loose type check that will descend into nested objects, checking that all properties are present. You may wish to alter this to perform strict type checking or implement a different form of deep object comparison if you are using objects.

Note Editor uses loose type checking by default as the values from the field input elements are read from the document, and thus will be strings. Please keep this in mind if you are implementing your own comparison function.

Type

fields.compare( submitted, original )

Define a function that will determine if a field's value should be submitted to the server when submitChanged is used for the submit option of the form-options.

Parameters:

Returns:

boolean:
If the data should be submitted to the server, false should be returned to indicate that the values are not the same. If the data should not be submitted to the server (dependent upon the submit option of the form-options) true should be returned to indicate the values are the same.

Example

Always submit a field's value, regardless of if it has changed or not:

var editor = new DataTable.Editor({
	ajax: '/api/staff',
	table: '#myTable',
	fields: [
		{
			label: 'Name:',
			name: 'name',
			compare: function (a, b) {
				return false;
			}
		}
	]
});