Expand my Community achievements bar.

SOLVED

Testing for validation errors

Avatar

Level 2

A simplified version of what I'm trying to do:

  • A form contains a required input field, a standard submit button to perform some actions and trigger an email submit button, and a subform set to Hidden.
  • If the user fills in the input field and clicks Submit, the hidden subform is displayed and the email submit is triggered.
  • If the user clicks Submit with the input field empty, I want the error message to display but the subform to stay hidden and the email event to not trigger.

What happens is that the error message displays, the email event does not trigger, but I can't figure out how to prevent the hidden subform becoming visible. Ideally, I'd like to be able to test the validation check and branch depending on the result. However, it seems that an execValidate doesn't return a code so placing it in a pre-submit event has no effect.

I could add code to manually test the field for null, but in the real world, this would result in dozens of extra lines of code and I was hoping to avoid that.

Button click event:

RealSubmit.event__click.submit.target="mailto:user@isp.com?subject=Test";

RealSubmit.execEvent("click");

sfHidden.presence = "visible";

Can anyone suggest where I might place the .presence line to accomplish what I want?

Thanks, Steve

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

You would need to wrap the script in an if statement that checks if the mandatory fields have been completed:

if (form1.execValidate() == true) {

     RealSubmit.event__click.submit.target="mailto:user@isp.com?subject=Test";

     RealSubmit.execEvent("click");

     sfHidden.presence = "visible";

}

Should work,

Niall

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

You would need to wrap the script in an if statement that checks if the mandatory fields have been completed:

if (form1.execValidate() == true) {

     RealSubmit.event__click.submit.target="mailto:user@isp.com?subject=Test";

     RealSubmit.execEvent("click");

     sfHidden.presence = "visible";

}

Should work,

Niall

Avatar

Level 2

Does indeed. Thanks so much for your prompt response!

Steve