Expand my Community achievements bar.

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

Avatar

Level 2

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

5 Replies

Avatar

Community Advisor

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

Avatar

Level 2

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?

Avatar

Community Advisor

@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

Avatar

Level 6

Hi, I checked your code in my local. Works fine for me. Looks like you have some other issue with your form as per your attachment. Click on the 'Details' button in your error message which says - 'The graphical component "Product*" has generated an error. That would help to identify the issue in your form.

 

Working code:

nms:newDelivery input form:

<leave name="leave">
<msgBox translatedExpr="'delivery label='+[@label]"/>
<check expr="@label!='test'">
<error>It is not possible to create a delivery with label 'test'</error>
</check>
</leave>

I can view the msgBox as below:

somasundaram_h_1-1733746044340.png


Error message:

somasundaram_h_0-1733746019174.png

 

Avatar

Level 2

Hi @isahore  and @somasundaram_h, thank you for taking the time to reply.

 

The error message which i shared previously is from the delivery properties tab (nms:delivery), where the error message works just fine (as i showed in the screenshot posted in my previous post). in that part, which works, i have this input:

 

<input label="Produkt* " required="true" xpath="@produktomrade">
<enter name="onChange">
<set expr="1" xpath="/ignored/@deliveryCodeParams"/>
</enter>
</input>

 

and at the bottom the leave part

 

<leave name="leave">
  <check expr="@produktomrade!=''">
    <error>Produkt field of delivery code parameters in general tab is empty, please update it with a value in order to save.</error>
  </check>
</leave>
 
Again, this above works.
 
So what i ve done is to try to replicate this for an input in the form view (xxx:Newsletter2019) using the same logic but with no result. 
 

<container>
<input required="true" xpath="@userPreference"/>

<static label="OBS: Choose correct opt-out category"
type="help"/>
</container>

 

and in the bottom

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

 

when i then create a delivery and the opt-out field is blank it still allows me to save with no error message. i ll attach a few screenshots for better clarity.

 

Thank you