Editor event submitSuccess
Editor event submitSuccess
It would be great if the Editor event submitSuccess also returned the action that was executed successfully. If you need to know the action you can't use submitSuccess right now.
My workaround is to use postSubmit and check whether the action was completed sucessfully like this. I found out that I definitely have to check for json.error and json.fieldErrors because if they exist you don't get all the other parameters that you may need to check for.
.on('postSubmit', function (e, json, data, action) {
if (! json.error && ! json.fieldErrors) {
if (action === 'remove') {
do something
}
if (action === 'edit') {
do something else
}
if ( action === 'create' &&
typeof json.data[0] !== 'undefined' ) {
do something else
}
}
});
Maybe this extension can be put into the next relase?!
Replies
You could use the
postCreate
,postEdit
andpostRemove
events separately.Alternatively, you could call a function that take the action value as a parameter and returns your common handler function as a closure, that way you can use a single function to handle postCreate/Edit/Remove if you wish and still have access to the action.
For example:
But I agree, in some cases it would be quicker to have the action value sent to the submitSuccess event.
Added to the enhancement list - it will be in 1.7.0.
Thanks for the suggestion!
Allan
Thanks Allan!
@rduncecb: Thanks for your comment! Looks like a good solution, too!
Once Allan will have implemented the change I guess postCreate, postEdit and postRemove are more or less redundant. I never used those events because you have code duplication in some cases (e.g. same logic for Create and Edit).