Unable to set "disabled" to checkboxlist / radiolist options

For now, OC can only disable whole checkboxlist, but it will be great, if we can set “disabled” for each option separatelly.

for example, in method getRecipientsOptions i will sent something like

function getRecipientsOptions() {
return [
    'item1' => [
       'This is main label',
       'This is description',
       'disabled' => true,
       'readonly' => true
     ],
    'item2' => [
       'This is main label',
       'This is description'
     ]
];

current behaviour sets “disabled” to all checkboxes, when field option disabled is set.
any other options is not reflected, only first two from options array.

with small change in october.form.js at line 69 (wink… nice line), we can disable this, for fields, where we tried to set “disabled”…

$('input[type=checkbox]:not(:disabled)', $field).prop('disabled', isDisabled);

and for correct “check all” and “uncheck all”

        checkAllCheckboxlist($field, flag) {
            $('input[type=checkbox]:not(:disabled)', $field)
                .prop('checked', flag)
                .first()
                .trigger('change');
        }

of course, we need to change partial _field_checkboxlist.php to reflect new options…
first of all, setting correct “option based” values
add this lines after line 91

$disabled = $readonly = false;
if (array_key_exists('disabled',$option)) $disabled = $option['disabled'] ? 'disabled="disabled"' : '';
if (array_key_exists('readonly',$option)) $readonly = $option['readonly'] ? 'onclick="return false"' : '';

this will fill out $disabled and $readonly for our specific option, when is processed…
and next somewhere in input field we need to print out new variables

     ...
     type="checkbox"
     id="<?= $checkboxId ?>"
     name="<?= $field->getName() ?>[]"
     value="<?= e($value) ?>"
     <?= $disabled ?>
     <?= $readonly ?>
     ...

this changes will results into this kind of checkboxlist
Snímka obrazovky 2024-08-10 233058


This is probably most requested funcionality…

Yes, indeed, this is a great design proposal. I adjusted it slightly below, so we can look for label key and know it is a complex definition (VS a simple definition).

function getRecipientsOptions() {
return [
    'item1' => [
       'label' => 'This is main label',
       'comment' => 'This is description',
       'disabled' => true,
       'readonly' => true
     ],

Send me a DM and I can show you how to contribute this feature, if you would like to collaborate on it.

Best regards

2 Likes

A field option definition has been created here, we will add this ability in v3.7

1 Like