How to reject if error on "Promise" in editor
How to reject if error on "Promise" in editor

Hi,
I want to reject the insert of a new entry if a condition is not met. For this I have an ajax call against the database to check the condition.
I do not know how to avoid "getting stuck in <<Uncaught (in promise)>>" if I do not call "resolve"...
Here is my javascript code
stepeditor.on("initSubmit", function(e,action) {
return new Promise( function ( resolve, reject ) {
$.ajax( {
url: "licencemodule_process",
type: 'POST',
data: {
stepid: (action=="create" ? null: stepid),
srcModuleid: stepeditor.field( 'tbladib_step.srcModuleid' ).val(),
},
success: function ( json ) {
var jsonArr = JSON.parse(json);
if (json.indexOf("failed")>0) {
alert("You do not have enough licences!!\n" + jsonArr.hint);
// if user wanted to create a new step ...
if (stepid == null) {
// in this case : close the form and exit ..
stepeditor.close();
return Promise.reject(false);
...
else // if ok --> create step
resolve( jsonArr.result == "success" );
This discussion has been closed.
Replies
I think this:
should just be:
That's not the issue though - what you would really need is a
try
/catch
around thesubmit()
method call since that is what is triggering theinitSubmit
event. How are you currently triggering the submit action?Allan
Hi,
it is triggered by a click on "New" on the corresponding Datatable
(i.e. "standard behavior")
When click on "edit" - and the licence is not OK, I reset the values back to initial ones and call the "resolve" - this works without problems.
It is just the "New" that poses problems - as I need to stop the insert of data into the corresponding table ..