I need to write javascript that says if Age is greater than 5 YR/ 0 MO, then make field Last Manufacture Recertification question required. The Age field is calculated based off the manufacture date and current date. I have tried have two fields (one required/ one not required) using field rules, but it doesn't work because the Last Manufacture Recertification is set to only appear when the equipment type is an SRD. The field rules breakdown because two different rules act on the same field. Can anyone help me write this if then statement in javascript? Any help is greatly appreciated.
Question
Question
Javascript to make field required based on value of another field.
Replies
In the Javascript section you can do something like this. Just give the field that you want required/no-required the class "chkReq" or adjust to your preference
It gets fancier when you want to remove the asterisk on the fly and put it back, depending on what the field contains.
$( document ).ready(function() { IF SOMETHING { $('.chkReq input').removeAttr('required'); } ELSE { $('.chkReq input').attr('required', true); } });
Sure. For the multi-line field use:
$('.chkReq textarea')
instead of input. Just put it right below the code for the input. It would be something like:
$( document ).ready(function() { IF SOMETHING { $('.chkReq input').removeAttr('required'); $('.chkReq textarea').removeAttr('required'); } ELSE { $('.chkReq input').attr('required', true); $('.chkReq textarea').attr('required', true); } });
Oh, of course. Thank you so much!!
Is there a way to add in the required icon when you add the attribute?
<span class="cf-required">*</span>
you can add the required icon using the following:
//q number $('#qxx label').append('<span class="cf-required">*</span>'); or //classname $('.classname label').append('<span class="cf-required">*</span>');
Can this be applied to more than one field if I use the same "chkReq" class ? It's working on the first field (a date field), but not the second (a multi-line field).
Thanks!
Validate field as required or optional using field rules is supported in new form designer with Forms 11 Update 3.
You can see other changes of Forms 11 Update 3 from https://support.laserfiche.com/kb/1014413/list-of-changes-for-laserfiche-forms-11-update-3 and get Forms 11 Update 3 from Laserfiche 11 package https://support.laserfiche.com/kb/1014263/software-versions-and-fixes-included-in-the-laserfiche-11-download-package.