Validate a form field in input form using <leave> and <check> | Community
Skip to main content
Level 2
December 4, 2024
Solved

Validate a form field in input form using <leave> and <check>

  • December 4, 2024
  • 1 reply
  • 1527 views

Hi Sirs,

 

I ve been trying to create a validation for a field consisting of drop-down button/enumeration with 5 options. The goal is: if a user creates a new delivery template and leaves the field empty then an error message must pop-up once user tries to press the save button. So far i haven't been successful tho. here is the relevant part of the form.

the input:

<container>
<input required="true" xpath="@userPreference"/>
<static label="NB: Choose opt-out based on what category the email belongs to." type="help"/>
</container>

 

and, in the bottom part of the form file, the leave+check part

 

<leave name="leave">
<check expr="@userPreference!=''">
<error>test_test</error>
</check>
</leave>
</form>

 

What am i missing? 

 

Cheers

Best answer by Cl4ud

Hi @isahore & @somasundaram_h,

Can you please help @pabloneruda further with their query?

Thanks!


Thank you Sukrity for bringing this up. Since it is not possible to render pop-up error messages in the form, i moved the mandatory field to the "delivery properties" section where i could implement the drop-down mandatory field i needed.

 

We can close this now 🙂

1 reply

isahore
Community Advisor
Community Advisor
December 6, 2024

Hi @pabloneruda,

 

In your <leave> tag you can print the value of the "@userPreference" xpath to double check what value it gets assigned:

 

<leave>
<msgBox translatedExpr="'user preference'+[@userPreference]"/>

<check expr="@userPreference!=''">
<error>test_test</error>
</check>
</leave>
</form>

 

Since you are using a dropdown, could be that the default value of this xpath is not blank if there is no selection made by the user.

Let me know if that helped.

 

BR,

Ishan

Level 2
December 6, 2024

Hello @isahore ,

 

thanks for your reply.

 

I have added the msgbox row but it didnt help, i still can either leave the field empty or choose among the 5 options, i can save the form with no problem 😕😕

 

<leave name="leave">
<msgBox translatedExpr="'user preference'+[@userPreference]"/>
<check expr="@userPreference!=''">
<error>test_test</error>
</check>
</leave>
</form>

 

I wonder if perhaps in the form view is not possible to create a error message?  coz in the delivery properties it is no problem to create it (see screenshot) while in the form view no success so far 😕😕

 

Have you ever managed to create an error message in the form view?

isahore
Community Advisor
Community Advisor
December 9, 2024

@pabloneruda, are you able to get the value of your selection displayed on message box pop-up? What do you see there?

Error message logic works for all input forms, OOTB and custom, equally. Maybe something else in your form is not letting the leave tag execute properly. Could you share more details, more of the form code - for example?

 

BR,

Ishan