field().enable()
Enable a field, allowing user input.
Please note - this property requires the Editor extension for DataTables.
Description
It can at times be useful to enable and disable a field, allowing and preventing the user from modifying the field's value. This method provides the ability to enable a field control for user input.
This is the inverse of the field().disable() method, which will disable a previously enabled field.
Note that the enable() method also provides the ability to enable a field, and extends that capability to being able to enable multiple fields in a single call. As such, these two methods can often be used interchangeably. The key difference is in the return value - this method will return a DataTable.Editor.Field instance, while the enable() method returns a DataTable.Editor instance. This can effect how you chain methods if you are using the returned value for chaining.
Type
field(…).enable( [toggle] )
Enable the field, allowing the end user to alter the field's value.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | toggle | Yes - default:true | |
Since 2.0: An optional toggle parameter which can be used to disable the field if | |||
Returns:
DataTable.Editor.Field: Field instance
Examples
Show a 'create' record form, but with a particular field enabled (it might have previously been disabled for example):
// Note that field().enable() returns a `DataTable.Editor.Field` instance, so
// the Editor methods must be used on the `editor` variable here
editor.field('account_type').enable();
editor
.buttons('Save')
.title('Save')
.create();Enable a field, and set a value for it (since the field is enabled, the user would be able to modify this value):
editor
.field('first_name')
.enable()
.val('Allan');Toggle a field based on its current state:
let field = editor.field('first_name');
field.enable(!field.enabled());