preSubmit not cancelling when returning false from an async/await handler

preSubmit not cancelling when returning false from an async/await handler

geometrygeometry Posts: 25Questions: 8Answers: 0

It seems that an async/await handler is not an expected argument for event handlers; e.g.

editor.on("preSubmit", async () => {
    try {
        return (await jQuery.ajax(...)) as boolean;
    } catch (e: any) {
        alert(e);

        return false;
    }
});

Is this type of programming structure acceptable when using event handlers?

Answers

  • allanallan Posts: 65,286Questions: 1Answers: 10,822 Site admin

    I would expect that to work okay. I've just tried making a little example and it works okay.

    Can you link to a test case showing the issue please? Also, what version of Editor are you using?

    Allan

  • geometrygeometry Posts: 25Questions: 8Answers: 0

    Hi Allan,

    Our company is using DataTables Editor v2.4.0.

    I have also looked at your example and it doesn't replicate the scenario I'm concerned with. Perhaps I wasn't clear in the description.

    In the scenario that I having problems with is that the async/await handler is returning false to cancel the submit process. It doesn't cancel the submit process, but instead cycles to run the async/handler again. It gets into an endless loop.

  • allanallan Posts: 65,286Questions: 1Answers: 10,822 Site admin

    A promise that resolves to false should still work okay - here is my example updated to show that.

    I've just had a look at the 2.4.0 code and there hasn't been any changes in that section between it an 2.5.0, so it should work there.

    Are you able to modify my example to demonstrate the problem or give me a link to a test case showing the issue?

    Thanks,
    Allan

Sign In or Register to comment.