Hi All,
I'm running into an issue trying to get conditional rules working correctly. Basically, I'm attempting to validate that once one field has been selected, either one of two child fields has content.
I'm listed a sample form and rule file below. The following form has a select with 3 options - Fruit, Candy, or Ice Cream. If the user selects either Fruit or Ice Cream, the conditional rule that a 'Name' needs to be provided for each one of those works perfectly. However, for Candy - I would like to give the user a list of options OR the ability to specify a new one.
{"name":"isCandy",
"serverTest":"snack EQ 2 AND (!Len(candyType) OR !Len(candyName))",
"clientTest":"$(\"[name='snack']\").getValue() == 2 && (!$(\"[name='candyType']\").val() === '' || !$(\"[name='candyName']\").val() === '')"
},
The Server side test validates correctly, and will error if no value is selected. However the clientTest doesn't appear to be working. Can anyone see something I'm overlooking?
FORM:
------------------------------------------
<form action="/index.cfm/?action=step2" method="post" enctype="multipart/form-data" id="form-step1" class="uniForm ">
<fieldset class="inlineLabels" id="cfU-C775D07C-E411-5B29-02901692DD0F9008">
<legend>Snack Time<span id='requiredFieldsTitle'><span class='red'>*</span> Required fields</span></legend>
<div class="cfu-fs-inner-wrap">
<div class="ctrlHolder">
<label for="snack" class="requiredField"><em>*</em> Snack Selector</label>
<select name="snack" id="snack" class="selectInput required" >
<option value="" selected="selected" class="">--- SELECT ---</option>
<option value="1" class="">Fruit</option>
<option value="2" class="">Candy</option>
<option value="3" class="">Ice Cream</option>
</select>
</div>
<div class="ctrlHolder">
<label for="fruitName" class="">Fruit Name</label>
<input name="fruitName" id="fruitName" value="" size="35" type="text" class="textInput" />
</div>
<div class="ctrlHolder">
<label for="candyType" class="">Candy Type</label>
<select name="candyType" id="candyType" class="selectInput" >
<option value="" selected="selected" class="">--- SELECT ---</option>
<option value="1" class="">Snickers</option>
<option value="2" class="">Mars</option>
</select>
</div>
<div class="ctrlHolder">
<label for="candyName" class="">Candy Name</label>
<input name="candyName" id="candyName" value="" size="35" type="text" class="textInput" />
</div>
<div class="ctrlHolder">
<label for="flavorName" class="">Flavor Name</label>
<input name="flavorName" id="flavorName" value="" size="35" type="text" class="textInput" />
</div>
</div>
</fieldset>
<div class="buttonHolder">
<button type="submit" class="primaryAction " name="validate-step1" id="validate-step1">Step 2 ></button>
</div>
<input type="hidden" id="formID" name="formID" value="form-step1" />
</form>
RULES:
-------------------------------------------
{
"validateThis" : {
"conditions" : [
{"name":"isFruit",
"serverTest":"snack EQ 1",
"clientTest":"$(\"[name='snack']\").getValue() == 1"
},
{"name":"isCandy",
"serverTest":"snack EQ 2 AND (Len(candyType) OR Len(candyName))",
"clientTest":"$(\"[name='snack']\").getValue() == 2 && ($(\"[name='candyType']\").length() || $(\"[name='candyName']\").length())"
},
{"name":"isIceCream",
"serverTest":"snack EQ 3",
"clientTest":"$(\"[name='snack']\").getValue() == 3"
}
],
"objectProperties" : [
{"name":"snack","desc":"Snack Type",
"rules": [
{"type":"required","failureMessage":"You must select a snack"}
]
},
{"name":"fruitName","desc":"Name of a Fruit",
"rules" : [
{"type":"required","condition":"isFruit","failureMessage":"You must specify a fruit name"}
]
},
{"name":"candyType","desc":"Standard Candy",
"rules" : [
{"type":"required","condition":"isCandy","failureMessage":"You must Select a Candy - or - specify one below"}
]
},
{"name":"candyName","desc":"Optional Candy",
"rules" : [
{"type":"required","condition":"isCandy","failureMessage":"You must Specify a Candy - or - select one above"}
]
},
{"name":"flavorName","desc":"Name of an Ice Cream Flavor",
"rules" : [
{"type":"required","condition":"isIceCream","failureMessage":"You must specify a Flavor"}
]
}
]
}
}