Javascript validation of fill-in choice control

  • 31 March 2018
  • 1 reply
  • 6 views

Badge +1

Hello All,

I have a form which has a number of dropdown choice controls which allow for "fill-in" text entry as well.  Some of these controls need to have conditional validations rules set (i.e. if choice above = "xxx" then this is required") and i am trying to figure out the correct javascript syntax to do so.  

I can easily use javascript to conditionally validate the control to check if no dropdown selection has been made, but how can I access the "fill-in" entry box to check if that is Null when the corresponding radio box is selected...

See pic below for example...

Hope someone can point me in the right direction


1 reply

Userlevel 5
Badge +14

Just using the Named Control in your formula will result in the value of whichever field (Drop Down -or- Fill In) is currently selected. 

You can see this easily simply using the Named Control as the formula for a Calculated Control, and looking at the output. 

214151_pastedImage_1.png

(Naming a choice control)

214152_pastedImage_2.png

(Adding the Named Control reference to a Calculated Control's Formula)

214153_pastedImage_3.png

(Showing the value when an option is selected and active)

214154_pastedImage_4.png

(Showing the value when the fill in is active) 

So, as shown, using the Referenced Named Control of the Choice in question will always result in the correct value being passed to your Rule. 

If you're trying to figure out which portion of the control is active (the Fill In section or the default Choice section), you'll need to break out the javascript, and because I'm not sure how you have your rules set up, it would be a bit difficult to give you an adequate explanation otherwise. 

Ultimately, this: 

NWF$("#" + optionsID).siblings(".nf-choice-control-radio-button").find("input").prop("checked")

will tell you whether or not the top 'Default Choice' control is active, but again, how you use that is entirely up to how your rules are set up. 

It should be noted that this assumes you have the 'Store Client ID in Javascript Variable' option set to Yes and the variable name set to 'optionsID' 

214155_pastedImage_15.png 


Reply