Greetings there!
Use Case -
So field A is a single select containing only two options: "Yes", "No".
Field B is a paragraph field.
Expected behavior -
- If user selects "Yes" in field A, field B becomes visible. Otherwise, if field A is "No" or empty, then field B is hidden.
Simple, right?
But I can't get it to work!
The following script works when Field A is a multi-select, but not for a single select.
(function() {
var field = getFieldById("customfield_A");
var values = field.getValue();
if (values && values.length > 0 && values.some(function(v) {
return v.value === "Yes";
})) {
getFieldById("customfield_B").setVisible(true);
} else {
getFieldById("customfield_B").setVisible(false);
}
})();
So on attempting to make thids work I thought this should, but it doesn't for some reason:
const selected = getFieldById("customfield_A").getValue(); // null | { id, value }
if (selected?.value === "Yes") {
getFieldById("customfield_B").setVisible(true);
} else {
getFieldById("customfield_B").setVisible(false);
}
Any insight will be greatly appreciated.
Cheers!