Feature No Code Attached Yet
avatar daycounts
daycounts
22 Jul 2023

Steps to reproduce the issue

Load a radio buttons list using HTMLHelper('select.radiolist') and pass a CSS class in the attributes.

$options=array();
$o = new stdClass();
$o->value = 1;
$o->text = 'option 1';
$options[] = $o;

$attribs=array();
$attribs['class'] = 'MyCLass'
HTMLHelper::_('select.radiolist', $options, 'fieldname', $attribs);

Expected result

Both the form-check-input and MyCLass should be merged in one class attribute

<div class="controls">
  <div class="form-check form-check-inline">
    <input type="radio" class="form-check-input MyCLass"  name="fieldname" id="fieldname1" value="1">
    <label for="fieldname1" class="form-check-label" id="fieldname1-lbl">option 1</label>
  </div>
</div>

Actual result

class attribute is duplicated.

<div class="controls">
  <div class="form-check form-check-inline">
    <input type="radio" class="form-check-input"  name="fieldname" id="fieldname1" value="1" class="MyCLass">
    <label for="fieldname1" class="form-check-label" id="fieldname1-lbl">option 1</label>
  </div>
</div>

Modern browser will remove the second instance of the class attribute and that can cause developper headaches...
This is in particular an issue with Virtuemart that is loading some radio list and then some script is looking for the selected option based on a passed class but the class has been removed by the browser (or some cleanup / compress html scripts)

System information (as much as possible)

Php 8.1
Joomla 4.3.3

Additional comments

avatar daycounts daycounts - open - 22 Jul 2023
avatar daycounts daycounts - change - 22 Jul 2023
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 22 Jul 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 22 Jul 2023
avatar brianteeman
brianteeman - comment - 10 Aug 2023

Shouldnt the code be as follows?

$attribs['class'] .= 'MyCLass'

avatar Quy
Quy - comment - 10 Aug 2023

.= is for string concatenation. It is fine since it is for an array.

avatar daycounts
daycounts - comment - 10 Aug 2023

That would not work since the function Select.radiolist is hardcoding the class "form-check-input" to the input
You can refer to file : /libraries/src/HTML/Helpers/Select.php

if (is_array($attribs)) { $attribs = ArrayHelper::toString($attribs); }

$html .= '<input type="radio" class="form-check-input" name="' . $name . '" id="' . $id . '" value="' . $k . '" ' . $extra . $attribs . '>';

avatar Hackwar Hackwar - change - 11 Aug 2023
Labels Added: bug
avatar Hackwar Hackwar - labeled - 11 Aug 2023
avatar brianteeman
brianteeman - comment - 1 Sep 2023

I am changing this from a bug to a feature request. The HTMLHelper('select.radiolist') does not support the addition of an extra css class as you have seen so its not a bug

avatar brianteeman brianteeman - change - 1 Sep 2023
Labels Added: Feature
Removed: bug
avatar brianteeman brianteeman - unlabeled - 1 Sep 2023
avatar brianteeman brianteeman - labeled - 1 Sep 2023
avatar richard67 richard67 - close - 27 Apr 2024
avatar richard67
richard67 - comment - 27 Apr 2024

Closing as having a pull request. Please test #43392 . Thanks in advance.

avatar richard67 richard67 - change - 27 Apr 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-04-27 15:52:02
Closed_By richard67

Add a Comment

Login with GitHub to post a comment