preSubmit
Pre-submit of data to server event (cancellable).
Please note - this property requires the Editor extension for DataTables.
Description
Pre-submit event for the form, fired just before the data is submitted to the server. This event allows you to modify the data that will be submitted to the server. It is also cancellable by using return false; in the event handler. This will stop the form from being submitted.
Note that this event runs after the formatData callback function (3rd parameter) of the submit() API method, if that function has been defined which submit() is called. If you need to modify the data of the form using the API methods, please use the initSubmit event.
If you are using Editor in local table editing mode (i.e. without the ajax option), Editor will automatically assign a row id to newly created rows in the table based on the current timestamp. This event provides the option to customise the id set by simply assigning the value that you wish to the id property data source (idSrc - typically this is DT_RowId unless otherwise specified).
Event naming / backwards compatibility note
Prior to Editor 1.3, events were prefixed with the string on and this event was called onPreSubmit. That event name can still be used, and will function exactly the same way as the event documented here. The new name is used for simplicity and coherence with the event naming conventions in DataTables.
Type
function( e, data, action )
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | e | No | |
Event object | |||
| 2 | data | No | |
The data object that will be submitted to the server | |||
| 3 | action | No | |
The action type for this submit - | |||
Returns:
boolean:
Return false to stop the form being submitted.
Example
Cast a field as a number type:
editor.on('preSubmit', function (e, data, action) {
$.each(data.data, function (key, values) {
data.data[key]['numberField'] = parseInt(values['numberField'], 10);
});
});Related
The following options are directly related and may also be useful in your application development.