Jump to content

Inputfield Checkboxes list


Recommended Posts

I had a look at this, and it seems it isn't possible to directly set the optionAttributes property of inputfields that extend InputfieldSelect. That is probably why @kixe made this module.

But what you can do is use a hook to remove the existing options, and then add them back with some attributes...

$wire->addHookBefore('InputfieldCheckboxes::render', function(HookEvent $event) {
    $inputfield = $event->object;
    // Only for a specific field
    if($inputfield->hasField != 'your_field_name') return;
    $options = $inputfield->options; // Get the existing options
    $inputfield->options = []; // Remove all the existing options
    // Add the options back with attributes
    foreach($options as $value => $label) {
        // Set whatever attributes you want as $key => $value in the last argument of addOption()
        $inputfield->addOption($value, $label, ['disabled' => 'disabled', 'data-foo' => 'bar', 'class' => $this->sanitizer->pageName($label, true)]);
    $event->return = $inputfield;


  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...