Confirmation popup timeout triggers function from "Save"

Hello,

Can someone confirm this is the right way to trigger a Confirmation popup in the SDK?

The popup itself works fine but I realized that, whenever the 10sec time out is triggered, the function that should happen when the user clicks on “Create” (createFct()) is triggered as well.

function confirmCreation(
  a,
  paramxyz
) {
  if (paramxyz === "") {
    notify("warning", "Fill out all required fields.");
    return;
  }
  client.interface
    .trigger("showConfirm", {
      title: "Please confirm",
      message: `Are you sure?`
    })
    .then(function(result) {
      if (result = "Save") {
        createFct(
          a,
          paramxyz
        );
      }
    })
    .catch(function(error) {
      console.log(error);
      notify("error", `Confirmation failed. Contact support: "${error.response}".`);
    });
}

Update: For some reason, it looks like whenever the popup is canceled or times out, it returns both the intended value (e.g. “Cancel”) and “OK”…?

From console.log(result):

image

For now, I stringify result and search for the message (e.g. “Cancel”) if my if();

stringResult.includes("Cancel") === true

Hi Alex,

This is in fact the correct way to use it. then will always get triggered if there are no errors.

client.interface
    .trigger("showConfirm", {
      title: "Please confirm",
      message: `Are you sure?`
    })
    .then(function(result) {
    /** result.message would return either "OK" or "Cancel" or "Request timed out" based on user input. You should check it in the next line **/
      if (result.message === "OK") { // This is correct. 
        createFct(
          a,
          paramxyz
        );
      }
    })
4 Likes

Hey, Sorry I could not reproduce this. Chrome DevTools generally prints the console log at a particular time. But when you extend it, it shows you the latest value. As long as you check result.message for a particular case, it should be fine. Please check the code above for reference.

1 Like