event.stopPropagation() on onEvent function()

Hi there!

Is there an option to use event.stopPropagation() in AppLab?

As a simple example:

  • I have a click event on a screen
  • I have a click event on a button on that screen.
  • I do NOT want the screen event to run if the click happened on the button.

Welcome to the Forums!

First of all, App Lab isn’t a full JavaScript environment, and some things that work in browser JavaScript may not necessarily work in App Lab, such as event.stopPropagation().

To solve your problem, you could use a variable in the code to check if the screen element clicked was the button, or the screen itself, along with a setTimeout function to reset the variable.

var wasLoginClicked = false;
onEvent("btnSigIn", "click", function() {
  setScreen("Register");
  wasLoginClicked = true;
  setTimeout(function() {
    wasLoginClicked = false;
  }, 0);
});
onEvent("Login", "click", function() {
  if (wasLoginClicked) return;
  console.log("Only run this function if the click happened outside the button");
});

Also, please post your code as text and not images, it helps speed up the debugging process rather than manually typing in all of the code.