Return false doesn't stop firing next actions on mobile page. Any solution?

  • 1
  • Question
  • Updated 3 years ago
I have a situation in mobile page builder. I have a skuid button to run multiple action. First action is to run javascript snippet validation rule for character limit check, required field check and check for valid email. When limit exceeds or required field empty or  invalid email, javascript returns false and on-error action for  the first action is block UI and show error message, but it still fires next action. 
Is there any way to stop firing next action in mobile page builder, if a rule returns false.


Multiple actions on button:


Javascript snippet 'validStep1Fields': 

//Define boolean variables
var limitExceeded = false; var empty = false; var validEmail = true; //Validate Email format with Regex var validateEmail = function(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); }; var mergedRegisteredFields = $.extend({}, clientModel.registeredFields, pmComtactModel.registeredFields, ndContactModel.registeredFields, childContactModel.registeredFields); $.each(mergedRegisteredFields, function(i,f) { var dt = f.metadata.displaytype; var el ; if(dt == 'TEXTAEA') { el = 'textarea' ; } else if(dt == 'CURRENCY' || dt == 'TEXT' || dt == 'STRING' || dt == 'EMAIL'){ el = 'input'; } var temp = f.element.find(el); //console.log(temp); var fieldValue = temp.val(); console.log(fieldValue); //temp.removeClass('sff-required-field-border'); var limit; if(f.metadata.length) limit = (dt == 'TEXTAREA'? 501 : f.metadata.length); if(fieldValue && fieldValue.length > limit) { limitExceeded = true; temp.addClass('sff-required-field-border'); } if (f.required) { //console.log(f); empty = /^\s*$/.test(temp.val()); if(!fieldValue || empty) { empty = true; temp.addClass('sff-required-field-border'); } } if(fieldValue && dt == 'EMAIL' && !validateEmail(fieldValue)) { validEmail = false; temp.addClass('sff-required-field-border'); } }); if(limitExceeded || empty || !validEmail){ return false; } else{ return true; }
Photo of Pawan Lohani

Pawan Lohani

  • 284 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of J.

J., Official Rep

  • 7,470 Points 5k badge 2x thumb
Pawan,

Returning false should jump to the "on-error actions" branch if one is defined or stop the sequence completely if one isn't defined. If you comment out everything in your snippet and just return false, is this the behavior that you observe? If so, I would add a console.log in both branches of the if/else at the bottom, just to make sure that you are getting the expected branch to return.

If returning false doesn't halt the sequence, which version of Skuid are you running?