ClientTest condition on NotInList rule

45 views
Skip to first unread message

James Buckingham

unread,
Feb 21, 2011, 2:31:25 PM2/21/11
to valida...@googlegroups.com
Hi group,

I want to add the following condition to my validation script....

<condition  name="checkDisabilityAllowance" serverTest="DisabilityAllowance()"
clientTest="$(&quot;[name='DisabilityAllowance']&quot;).getValue() == 'Yes';"  />
</conditions>

<property name="KnownDisability" desc="The Student has a known disability">
<rule type="NotInList" contexts="disability" condition="checkDisabilityAllowance" failureMessage="validation_invalidAllowanceSelection_required"> <param name="list" value="A" />
</rule>
</property>

So basically if someone selected "Yes" for the allowance then they're not allowed to selected option A ( I've no disability ) from a dropdown.

Server-side is working but I've noticed that the client side script isn't loading into the page.

I spent a couple of hours looking through VTs code and from what I can work out it looks like the clientTest only outputs on one rule - "required".

Is that right, and if I wanted to change this how would I go about doing that?

Cheers,
James

adam drew

unread,
Feb 21, 2011, 2:41:20 PM2/21/11
to valida...@googlegroups.com
James,

This is a complicated one, and i do believe it was mentioned on the list at least once before..  you are correct that the only rule that was generating the client conditions was the Required type at this time.

The fix for this requires a bunch of work in abstractclientrulescripter, clientvalidator, clientscriptwriter_jquery and maybe another component.

Ironically enough that as you ask this question, it is exactly what I have been working for the past two days after I re-discovered the issue while working on my VT jquery plugin.

James, I'll let you know when i got a patch we can all try.

Unless anyone comes up with anything else in the mean time.


-Regards,
Adam
--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/validatethis?hl=en.

James Buckingham

unread,
Feb 22, 2011, 4:30:23 AM2/22/11
to valida...@googlegroups.com
Cool thanks a lot for the fast response again Adam.

As usual if you need a Guinea Pig to test stuff out on then please give me a shout :-). Happy to try things out. In the meantime I'll stick with the server side.

It's only to cover those people that try to play "smart" anyway :-)

Cheers,
James

Jason Durham

unread,
Dec 17, 2013, 1:28:46 PM12/17/13
to valida...@googlegroups.com
James,

Where you able to complete these enhancements?  I noticed I'm not getting client conditions for the "notregex" validation type.

Jason

James Buckingham

unread,
Dec 17, 2013, 2:08:17 PM12/17/13
to valida...@googlegroups.com
Hi Jason

This is going back a while now, both in time and versions, so I'd need to check our project to remind myself. 

From what I recall though we had to stick with server-side only for this.

Cheers
James
You received this message because you are subscribed to a topic in the Google Groups "ValidateThis" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/validatethis/jqwynsRMLbs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to validatethis...@googlegroups.com.

To post to this group, send email to valida...@googlegroups.com.

Jason Durham

unread,
Dec 17, 2013, 2:21:11 PM12/17/13
to valida...@googlegroups.com
Can you provide any insight (sorry.. I know it was been awhile) as to why it's difficult to implement client-side conditions for validation types other than "required"?  Inside of ClientScriptWriter_jQuery.generateValidationScript() there is a comment indicating client-side conditions are only for the "required" validation type.  However, I haven't stumbled upon the bit where it makes it especially challenging for different validation types.  

<!--- Conditional validations can only be generated for "required" type --->
<cfif (NOT (StructCount(arguments.validation.getCondition()) GT 0 OR
StructKeyExists(arguments.validation.getParameters(),"DependentPropertyName")) OR valType EQ "required")
AND StructKeyExists(variables.RuleScripters,valType)>
<cfset theScript = variables.RuleScripters[valType].generateValidationScript(arguments.validation,arguments.locale,arguments.formName) />
</cfif>

If I replace the red text with "1==1", then my condition makes it through to the client and works as expected.

Jason Durham

unread,
Dec 17, 2013, 2:26:47 PM12/17/13
to valida...@googlegroups.com
If it helps at all... I just looked through the commit history on this file and that comment (and logic) has existed since the project was added to GitHub.  Maybe Bob can recall why this was necessary?

Jason

Jason Durham


To unsubscribe from this group and stop receiving emails from it, send an email to validatethis...@googlegroups.com.

Bob Silverberg

unread,
Dec 17, 2013, 2:52:46 PM12/17/13
to ValidateThis
IIRC, it was a limitation in the jquery validation library that was being used. Maybe the library has advanced to remove that limitation? Basically, most of the client-side stuff that VT does is simply writing scripts that are then passed into the jquery validation plugin, so I don't think there is actually any conditional client-side logic in VT.

Of course I could be wrong about all of this as I haven't looked at VT, or any CF code for that matter, in close to 2 years.

It's nice to see that people are still finding VT useful. If anyone wants to take over ownership of it, please do. I am no longer maintaining it.

Cheers,
Bob

John Whish

unread,
Dec 17, 2013, 3:00:57 PM12/17/13
to valida...@googlegroups.com
I've just read the last few posts and forgive me if I'm going down the wrong path, but a solution might be to implement your own server and client side validator. It's relatively easy to do and you'll be able to add additional JavaScript logic into the client side validator you create. 

It's been a while since I looked at the code and don't use VT day to day anymore but I still use it on my pet projects and there are loads of sites out there that I built which use it so thank you Bob! Incidentally the develop branch has some minor amends to it I added which I really ought to merge into master, but the jQuery side of things hasn't been updated for a few years.

Cheers,

John

Jason Durham

unread,
Dec 17, 2013, 3:07:33 PM12/17/13
to valida...@googlegroups.com
I need to correct my last message... "If I replace the red text with "1==1", then my condition makes it through to the client but does not work as I hoped."  The validation for my field failed, but it also threw a JS error deep inside jQuery.  After correcting the data in the form input, I wasn't able to submit (constant jQuery errors).

I did some more digging around and it seems as though "depends" may still only apply to "required" validation type in the Validate plugin.

Jason

Jason Durham
Reply all
Reply to author
Forward
0 new messages