The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
conditional validation - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Modules / Other (https://forums.formtools.org/forumdisplay.php?fid=8) +--- Forum: Form Validation: JS + PHP (https://forums.formtools.org/forumdisplay.php?fid=18) +--- Thread: conditional validation (/showthread.php?tid=1562) |
conditional validation - egeller624 - Aug 26th, 2011 I have 3 separate radio buttons in my form with possible answers of "yes" or "no". I would like to make a text field required only if one or more of the radio buttons has been set to "yes" but I can't seem to figure out how to do that. This is what I tried so far but it's not working: Code: rules.push("if:c1_allergies=yes||c1_medical=yes||c1_medications=yes,required,Please provide medical details."); The conditional validation works fine for a simple if condition but what is the syntax for more complex logic like this? Or would I be better off with a separate function? Thanks. RE: conditional validation - Ben - Aug 26th, 2011 Hi egeller, Good question. The conditional logic for the RSV library is REALLY basic. I just added it because simple "if A=X then validate B" logic was common and wanted to cover that scenario with some simple syntax. In your case, it's a bit more complex so you'll need to use a custom function instead. For that, try something like this: Code: rules.push("function,mycustomfunction"); You will need to replace the if conditions with whatever code makes sense, depending on the field types. Sorry - that will take a little JS knowledge, but feel free to post back if you're not sure about it. Also the return statement will need to return the c1_medications DOM element as the first parameter. For more info, check out the "Custom Validation Rules" page in the help doc: http://www.benjaminkeen.com/software/rsv/standalone/ Good luck! - Ben RE: conditional validation - egeller624 - Aug 27th, 2011 Thanks for the reply, it works a treat! Just had to refresh my memory on JS syntax |