Hello @eberkland
Assuming you have the fieldname1, with two choices, fruits and vegetables, and the checkbox field fieldname2 with the choices bananas, strawberries, carrots, and lettuce. If the user selects fruits in fieldname1 you want to tick the bananas, strawberries choices in fieldname2, carrots, and lettuce choices if the user selects vegetables.
You can insert a calculated field in the form to be used as an auxiliary (you can hide it by ticking a checkbox in its settings), and enter the equation:
getField(fieldname2|n).setVal(IF(fieldname1=='fruits', ['bananas', 'strawberries'], ['carrots', 'lettuce']))
Or if you prefer to implement the equation with function structure:
(function(){
if(fieldname1=='fruits'){
getField(fieldname2|n).setVal(['bananas', 'strawberries']);
} else {
getField(fieldname2|n).setVal(['carrots', 'lettuce']);
}
})()
Best regards.
Thanks. What if there is an item that is not a fruit or a vegetable as an option in fieldname2, like say a pizza or a gallon of milk? Will those remain unchecked but remain as a selection option?
Hello @eberkland
The previous implementation ticks the fieldname2 choices based on the fieldname1 value. Other choices remain visible and selectable. If you need to hide or deactivate the unrelated options, you must implement a more complex equation.
If you need a custom coding service to implement a custom behavior, like the one described above, you can contact us directly through the plugin website. Contact Us.
Best regards.
Are we talking JQuery using .prop(‘checked’,true) similar to this question; https://ww.wp.xz.cn/support/topic/jquery-checkbox-propchecked-true/
Disregard last question. If everything else stays and is selectable. My problem is solved. You can mark as resolved. Thanks.
Hello @eberkland
Not exactly. The code .prop('checked',true) does not trigger the onchange events required to evaluate the dependencies and the equations. For this reason, the code in the other support thread must call the onchange event directly. The setVal method does both operations. It ticks the corresponding choices and triggers an onchange event at the end of the process.
However, it does not disable the other choices in the checkbox field.
Best regards.