It looks like you're on the right track with your implementation in PHPRunner for handling the dialog pop-up. However, there are a couple of things to check and adjust to ensure that the second control (the lookup field) gets properly enabled or disabled based on the selection made in the first control (the radio button).
Here's a refined version of your code with some comments to help clarify what’s happening:
Runner.Dialog({
title: 'Group Update',
fields: [{
name: 'Add or Remove Login Group?',
type: 'radio',
required: true,
horizontal: true,
options: [
['Adding', 'Add'],
['Removing', 'Remove'],
['Resetting', 'Reset To Default'],
['Deleting', 'Delete All']
]
},
{
name: 'Select Login Group',
type: 'lookup',
required: true,
options: [
[1, 'Group 1'],
[2, 'Group 2'],
[3, 'Group 3'],
[4, 'Group 4']
]
}],
afterCreate: function(popup, controls) {
// Set initial state of the second control based on the first control's value
this.toggleSecondControl(controls[0].getValue(), controls[1]);
// Add change event listener to the first control
controls[0].on("change", (e) => {
this.toggleSecondControl(controls[0].getValue(), controls[1]);
});
},
toggleSecondControl: function(selectedValue, secondControl) {
if (selectedValue === 'Deleting') {
secondControl.setDisabled(); // Disable the second control
} else {
secondControl.setEnabled(); // Enable the second control
}
},
ok: 'Update Login Group(s)',
cancel: 'Cancel',
beforeOK: function(popup, controls) {
// OK Button Code
}
});
return false;Key Adjustments:
Function Extraction: I've extracted the enabling/disabling logic into a separate function toggleSecondControl for better readability and code organization.
Initial State: The state of the second control is set right after it's created based on the initial value of the first control. This ensures that if the dialog is opened with a pre-selected option, the second control's state reflects that.
Change Event Binding: The event listener for the change event on the first control is properly set to call the toggleSecondControl function with the current value.
Additional Notes:
- Make sure that the names you are using for the controls in the
controls array are consistent with what you're assigning in the dialog configuration. - If you're still having issues, check the console for any JavaScript errors that may be occurring and ensure that the PHPRunner version you’re using supports the methods used in this example.
- Test the dialog to confirm that the second control's state changes as expected when you select different options from the first control.