Difference between revisions of "Making a field under a show/hide header mandatory"
(Created page with '==Problem== If a checkbox with a value of "Other" needs to show a mandatory "Other Description" field when "Other" is selected, and you make the "Other Description" field mandat…') |
(→See Also) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | {{JavaScript Syntax}} | ||
==Problem== | ==Problem== | ||
Line 12: | Line 13: | ||
(c) ''Allow Empty'' unchecked and<br /> | (c) ''Allow Empty'' unchecked and<br /> | ||
(d) the following in the [[JavaScript Validation]]: | (d) the following in the [[JavaScript Validation]]: | ||
− | !=<nowiki>''</nowiki>||!document.getElementById(<nowiki>'</nowiki> | + | !=<nowiki>''</nowiki>||!document.getElementById(<nowiki>'</nowiki>cf_12345_''n-1''<nowiki>'</nowiki>).checked |
So that if "Other" is the 5th value on the checkbox list, ''n-1'' = 4 | So that if "Other" is the 5th value on the checkbox list, ''n-1'' = 4 | ||
+ | |||
+ | ==See Also== | ||
+ | * [[Show/Hide Header]] | ||
+ | |||
+ | [[Category:Custom Fields]][[Category:JavaScript]][[Category:Validation]] |
Latest revision as of 09:40, 21 November 2014
This feature uses JavaScript syntax |
Problem
If a checkbox with a value of "Other" needs to show a mandatory "Other Description" field when "Other" is selected, and you make the "Other Description" field mandatory (uncheck Allow Empty), the page will not save when that field is left blank, even when it’s under a show/hide header that is only visible when "Other" is selected.
Solution
Where
(a) the checkbox field has n values, of which the "Other" value is the nth, and an HTML tag of onclick="_showhideheadercheckbox(12345,this,'Other');onlyonechecked(this)"
(b) the field to be made mandatory is under a Title Bar with the custom field id of 12345
The field to be made mandatory should have
(c) Allow Empty unchecked and
(d) the following in the JavaScript Validation:
!=''||!document.getElementById('cf_12345_n-1').checked
So that if "Other" is the 5th value on the checkbox list, n-1 = 4