node()
Get the container node for one or more fields.
Please note - this property requires the Editor extension for DataTables.
Description
When working with forms, you often want to interact directly with the form elements - for example, listening for a change event to take some action on update. This method will return the DOM element for the requested field, allowing standard jQuery / DOM manipulation of the field.
Note that the field().node() method introduced in Editor 1.3 provides the same functionality as this method for a single field, although this method extends that ability by being able to operate on multiple fields at the same time.
Type
node( [ fieldName ] )
Get the container node for one or more fields.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | fieldName | No | |
The field name that the node is requested for. To get the nodes for all fields in the form, do not pass a value in for this parameter. Note that the ability to use this parameter as an array or an empty value was added in Editor 1.3. | |||
Returns:
node or array: DOM element for the requested field, or an array of DOM elements if an array or no value was given as the fieldName parameter.
Examples
Dynamically add a class to a field's container:
$(editor.node('account_type')).addClass('account');Attach a change event handler to a field to show and hide an additional field on value selection:
$('input', editor.field('dept').node()).on('change', function () {
if (editor.field('dept').val() === 'Marketing') {
editor.show('marketing-section');
}
else {
editor.hide('marketing-section');
}
});Add a class to multiple field container elements:
$(editor.node(['account_type', 'account_name'])).addClass('account');