initCreate

Since: Editor 1.1

Form initialised for the create action event.
Please note - this property requires the Editor extension for DataTables.

Description

Create method activated event, fired when the create() API method has been called, just prior to the form being shown. Useful for manipulating the form specifically for the create state.

As of Editor 1.8 the init* events can return a Promise which is used to delay the execution of any further Editor code until the Promise has been resolved. This is useful if you need to make an Ajax call to the server for any additional information, validation, locking or any other async action.

Event naming / backwards compatibility note

Prior to Editor 1.3, events were prefixed with the string on and this event was called onInitCreate. 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 )

Parameters:

Returns:

Promise:
Optionally a Promise can be returned (jQuery or native). Editor will halt its code execution until the promise is resolved. If nothing is returned, Editor will immediately continue with its code execution.

Examples

Setting a default using initCreate:

editor.on('initCreate', function () {
	editor.field('myField').val('defaultValue');
});

Making an Ajax call - getting server defined defaults:

editor.on('initCreate', function (e) {
	return new Promise(function (resolve, reject) {
		$.ajax({
			url: '/api/defaults',
			success: function (json) {
				editor.vals(json);
				resolve(); // Editor continues after this
			}
		});
	});
});