postSubmit event inconsistency
postSubmit event inconsistency
The postSubmit
documentation specifies the parameters of an event handler should be( e, json, data, action )
.
It appears the event is triggered for success and failed ajax responses by Editor.prototype._submitSuccess
and Editor.prototype._submitError
respectively.
When fired from _submitError the parameters provided to the function are (xhr, err, thrown, submitParams)
, inconsistent with the documentation. It's also not possible to intercept the response and have it processed as if it was a successful submission in this case. As a consequence, if the ajax call responds with a 4xx code for validation errors (as the rest api does that i am working with) it can't be intercepted/tweaked for automatic processing by Editor as it would for the same response with a 20x code.
I was able to work around this by implementing my own processing function bound to the submitError event but it means implementing code to add errors to the Editor dialog myself. So that I don't have to re-implement code in the _submitSuccess function to add errors it would be nice if this functionality was refactored into a function I could call on an Editor instance to process a valid Editor error response JSON object
Replies
Very good point - thanks for flagging this up. This code was changed for 1.6 and it appears I neglected to update the documentation correctly.
I've added it to my bug tracker and will have it fixed for the next release of Editor. I'll post back here when done and with any updates.
Regards,
Allan
I've just committed a change that will be in Editoir 1.6.3 so that
postSubmit
will pass the same parameters for both the error and success conditions (per the documentation).However, if the server returns anything other than valid JSON, the JSON parameter passed into the event handler will be
null
and you don't have the option of modifying that (I couldn't find a good way to do that without breaking backwards compatibility).So what you have to do, if this is the situation for you, is to use your own
complete
function that will simply set theresponseJSON
parameter of the XHR object to be an empty object - e.g.Then Editor won't fall into its error state.
I've updated the documentation to say:
I'm going to make the 1.6.3 release today, and 1.6.3+ will be required for this to work correctly.
Thanks again for flagging this up!
Allan
Excellent! Thanks for replying when you had a fix. I'll give 1.6.3 a whirl and see about removing my workaround.
I have no need for a
complete
function, I simply need to restructure the response into something suitable for Editor to consume and let it do its thing.