I'm trying to convert an old form built in the Classic Form Designer to a new form built in the Modern Form Designer. The original form has a drop-down list of Departments and a radio button list of Types of Payment Requests (APG-Acct, APG-Wire-Xfr, and 5 other types). The purpose of hiding some of the Types of Payment Requests is that some departments are not allowed to use certain Types of Payment Requests.
JavaScript in Classic Form Designer that works:
$('.ddDept select').change(function () {
if ($(this).val() == "Human Resources"){
// if Human Resources is selected in the Department drop down...
$("input[type=radio][value=\"APG-Acct\"]").parent().hide();
$("input[type=radio][value=\"APG-Wire-Xfr\"]").parent().show();
} else if ($(this).val() == "Housing Agency"){
// if Housing Agency is selected in the Department drop down...
$("input[type=radio][value=\"APG-Acct\"]").parent().hide();
$("input[type=radio][value=\"APG-Wire-Xfr\"]").parent().show();
} else if ($(this).val() == "Planning Department"){
// if Planning Department is selected in the Department drop down...
$("input[type=radio][value=\"APG-Wire-Xfr\"]").parent().show();
} else {
// if any other department is selected, hide these request types
$("input[type=radio][value=\"APG-Acct\"]").parent().hide();
$("input[type=radio][value=\"APG-Wire-Xfr\"]").parent().hide();
}
I'm sure this code can be consolidated into fewer lines of code, but it grew over time and I didn't take the time to narrow it down each time a change was requested.
I tried using the following in the Modern Form Designer, but I realize the hideFields with index is meant to be used with table and collection fields.
const formFields = {
RequestTypeFieldId: { fieldId: 7 },
ddDeptFieldId: { fieldId: 72 }
};
const updateRequestCheckboxes = async (formFields) => {
if (formFields.ddDeptFieldId == "Human Resources") {
// hide APG-Acct radio button
await LFForm.hideFields([{fieldId: 7, index: 5}]);
} else if (formFields.ddDeptFieldId == "Housing Agency") {
await LFForm.hideFields([{fieldId: 7, index: 5}]);
} else {
// hide APG-Acct and APG-Wire-Xfr radio buttons
await LFForm.hideFields([{fieldId: 7, index: 5}, {fieldId: 7, index: 6}]);
}
}
LFForm.onFieldBlur(function() {updateRequestCheckboxes();}, formFields.ddDeptFieldId);
I suppose one way around this is to display an error message in an HTML field if a department selects a Type of Payment Request they are not allowed to submit. However, I'd rather not display options they aren't allowed to select.