add()
Add a new field to the form.
Please note - this property requires the Editor extension for DataTables.
Description
Fields in an Editor form can be dynamically added and removed from the form at any point, using this method and the clear() method.
By default, fields added using this method are automatically appended to the end of the form. As of Editor 1.5.6 you can optionally use the second parameter to determine where in the form's field order the new field should be inserted, or, for older versions, use the order() method to change the field order after the new field has been added.
You may also wish to use hide() if you do not wish the field to be visible immediately - call hide() with the second parameter set to false to disable animation.
Fields are typically set up during instance initialisation using the fields configuration option (which calls this API method internally) but this option provides the flexibility to modify the fields in the form - for example you might wish to ask for an extra input if a particular option is selected in a select list.
Type
add( config [, after ] )
Add a new field to the form.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | config | No | |
Field configuration object or an array of field configuration objects which will all be added to the form. | |||
| 2 | after | Yes | |
Since 1.5.6: Position in the form that the new field should be inserted into. This can be one of:
| |||
Returns:
DataTable.Editor: Editor instance
Examples
Add a single field to an Editor instance with basic name and label information. Note that this example makes use of the chaining aspect of Editor's API:
var editor = new DataTable.Editor({
ajax: 'php/index.php',
table: '#example'
}).add({
label: 'Name:',
name: 'name'
});Add a field to an existing Editor instance with extra information:
editor.add({
label: 'Name:',
name: 'name',
data: 'user_name',
fieldInfo: 'Enter the system user name (first name + last name)'
});Insert at the start of the form:
editor.add(
{
label: 'Name:',
name: 'name'
},
null
);Insert after another field:
editor.add(
{
label: 'Middle name(s):',
name: 'middle_name'
},
'first_name'
);