Fixed "listitemclass" attribute has no effect in checkbox choice formatter

Painbaker

Well-known member
Affected version
2.3.6
The listitemclassattribute in the checkbox tag processor is ignored. This attribute is expected to behave similarly to the radio tag processor.


Checkbox renderer does not call processAttributeToNamedHtmlAttribute() for listitemclass. Instead, it hardcodes the class as inputChoices-choice in the li element:

Radio renderer:

PHP:
    public function formRadio(array $controlOptions, array $choices)
    {
         ....
        $choiceFormatter = function (array $choice, array $dependent) use ($name, $readOnly, $value, $standalone)
        {
            ....
            $listItemClass = $this->processAttributeToNamedHtmlAttribute($choice, 'listitemclass', 'class', 'inputChoices-choice', true);
            $attributes = $this->processUnhandledAttributes($choice);

            if ($label !== '')
            {
                $label = "<span class=\"iconic-label\">{$label}</span>";
            }

            $radioHtml = "<label class=\"{$labelClass}\"{$titleAttr}{$tooltipAttr}>"
                . "<input type=\"radio\" name=\"$name\"{$valueAttr}{$selectedAttr}{$readOnlyAttr}{$attributes} />"
                . "<i aria-hidden=\"true\"></i>{$label}</label>{$hint}{$dependentHtml}{$extraHtml}{$afterHint}";

            if ($standalone)
            {
                return $radioHtml . "\n";
            }
            else
            {
                return "<li{$listItemClass}>{$radioHtml}</li>\n";
            }
            ....
        };
}

Checkbox renderer:
PHP:
    public function formCheckBox(array $controlOptions, array $choices)
    {
        ...
        $choiceFormatter = function (array $choice, array $dependent) use ($name, $readOnly, $value, $standalone)
        {
            ...
            $attributes = $this->processUnhandledAttributes($choice);

            if ($label !== '')
            {
                $label = "<span class=\"iconic-label\">{$label}</span>";
            }

            $checkboxHtml = $defaultValueInput . "<label class=\"{$labelClass}\"{$titleAttr}{$tooltipAttr}>"
                . "<input type=\"checkbox\" {$nameAttr}{$valueAttr}{$selectedAttr}{$readOnlyAttr}{$attributes} />"
                . "<i aria-hidden=\"true\"></i>{$label}</label>{$hint}{$extraHtml}{$dependentHtml}{$afterHint}{$afterHtml}";

            if ($standalone)
            {
                return $checkboxHtml . "\n";
            }
            else
            {
                return "<li class=\"inputChoices-choice\">{$checkboxHtml}</li>\n"; // <----
            }
            ....
        };
...
}
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.8).

Change log:
Support the "listitemclass" attribute when rendering checkboxes
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom