field().input()
Get the input node(s) for the field.
Please note - this property requires the Editor extension for DataTables.
Description
When working with forms, you often want to interact directly with the form's value input elements - for example, you might wish to listen for a change event to take some action when the user toggles a value change. This method will return a Dom instance that contains all of the form input elements from the field.
Please note that all input element types are returned, regardless of the element type. For example, input, textarea and select elements are all considered to be form input elements.
Additionally, if an action on field value change is required, consider the dependent() method which can be used to reduce the amount of code you need to write when one field is dependent upon another.
Type
field(…).input()
Get the input node(s) for an individual field.
Returns:
Dom:
Dom instance that contains the input elements for the requested field.
Please note that prior to Editor 3, this method would return a `jQuery` instance.
Examples
Dynamically add a class to a field's user interaction element:
editor
.field('account_type')
.input()
.addClass('account');Attach a change event handler to a field to show and hide an additional field on value selection:
// Note that `dependent()` can also be used to achieve this
editor
.field('dept')
.input()
.on('change', function () {
if (editor.field('dept').val() === 'Marketing') {
editor.show('marketing-section');
}
else {
editor.hide('marketing-section');
}
});