cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Not applicable

JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Scenario

Consider a List/Task/Workflow start form, where in the form contains a list look up control and a single line control. The list look up control is mandatory field and if user selects one particular value in the look up, the single line field will become mandatory.

Example

The list lookup control fetches values from list called, ‘Country’. Consider the items in the list ‘Country’ are:

  1. India
  2. Australia
  3. UK
  4. USA
  5. Others

If the user selects ‘Others’ then the single line control should be made as mandatory field. One of the ways to achieve this functionality is by using custom JavaScript validation

Solution

Step 1: Consider that the form resemble as shown in the below screenshot:

1.png

Step 2: Go to the settings of the lookup control and in the advanced section, set ‘Store Client ID in JavaScript variable’ to ‘Yes’ and give a valid variable name as shown below

1.png

Step 3: Go the setting of the single line control and in the validation section set ‘Use custom validation’ to Yes and provide the ‘Custom validation function’ name and the valid ‘Custom error message’

1.png

Step 4: Now to go to form setting from the top ribbon and navigate to Custom JavaScript tab

1.png

Step 5: Add this function in the Custom JavaScript function

//Check if Country name is mentioned

function CheckIfOtherCountry(source, arguments) {

try {

        var selectedCountry = NWF$("#" + ddlPicker+ 'option:selected');

        var selectedCountryValue = selectedCountry.text();

        arguments.IsValid = true;

        if (selectedCountryValue == "Others") {

                arguments.IsValid = false;

            }

}

catch (err) {

}

}

That’s it. You form is ready to go!!!   

Thanks to Prajna Priyadarshini‌ for providing valuable suggestions for this document.

Labels: (3)
Reply
13 Replies
Not applicable

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Thanks for contributing this Nidish. You'll be happy to know, however, that this can now be achieved without the need for custom JS at all.

Nintex Forms now includes Validation Rules which allow you to achieve the same result code free. If, for instance, your Lookup control is named "Country" you would set up a validation rule on the Single Line Text control with the condition as follows:

     parseLookup(Country)=="Other" && {Self}==""

The ParseLookup function returns just the text portion of the Lookup control without the ID so can be compared to the string "Other".

Reply
Not applicable

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Thanks for providing this valuable suggestion. Really useful

0 Kudos
Reply
Not applicable

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Go to Settings of the Single line of text control

1) Validation Settings > Required> Expression

2) (Country)=="Other"

0 Kudos
Reply
harfmt
Nintex Newbie

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Hi Daniel

Is parseLookup a function? I can't find that anywhere. I also tried the java and couldn't get that to work either.

0 Kudos
Reply
harfmt
Nintex Newbie

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Hi Kavisha

Do you mean

1) go to the settings for the Single Line Textbox -> Validation -> Regular expression

2) (Country)=="Other"

This didn't work for me.

0 Kudos
Reply
Not applicable

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Hi Joanne,

Yes. parseLookup is a runtime function. You will find it in the Runtime Functions tab in the formula builder when you set a condition in the Rules pane.

-DK

0 Kudos
Reply
harfmt
Nintex Newbie

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

Thanks Daniel.

I’ve been using the following which has worked fine in the web form but is definitely not working in the mobile app form.

Country=="Other" && <javascript:void(0);>==""

So I’ll try this now that I understand where I can find it.
parseLookup(Country)=="Other" &&
==""

Why do you think the option I’m using is working in the web form and not the mobile app form?

Kind Regards,

Joanne Morris

Technology Systems Analyst

Fleet Technology

Thiess Pty Ltd

179 Grey Street | South Bank QLD 4101

Locked Bag 2009, South Brisbane QLD 4101

T +61 7 3002 9428

M 0409 782 060

E jmorris@thiess.com.au<mailto:jmorris@thiess.com.au>

www.thiess.com.au<http://www.thiess.com.au/>

0 Kudos
Reply
Not applicable

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

JavaScript is not supported in the Nintex Mobile App. It's not a browser, it's a truly native app.

0 Kudos
Reply
harfmt
Nintex Newbie

Re: JavaScript To Validate Single Line Field Based On List Lookup Control Value - Nintex Form 2013

So there is no way of embedding rules into the app form?

Kind Regards,

Joanne Morris

Technology Systems Analyst

Fleet Technology

Thiess Pty Ltd

179 Grey Street | South Bank QLD 4101

Locked Bag 2009, South Brisbane QLD 4101

T +61 7 3002 9428

M 0409 782 060

E jmorris@thiess.com.au<mailto:jmorris@thiess.com.au>

www.thiess.com.au<http://www.thiess.com.au/>

0 Kudos
Reply