I am stuck with class
JHtmlSelect's function
option() where it seems to be possible to pass additional arguments via
optKey and
optText to override the default arguments
value and
text. I am trying to add a datalist to a text input field with the data list entries having more than just the
value-attribute like so:
<input type="text" id="jform_myfield" list="jform_myfield_datalist" .../>
<datalist id="jform_myfield_datalist">
<option value="SLG1" data-value="1" data-...="...">SLG1</option>
<option value="SLG2" data-value="2" data-...="...">SLG2</option>
<option value="SLG3" data-value="3" data-...="...">SLG3</option>
</datalist>
Following the function documentation (at least as how I can understand it conceptionally) I pass the following data to JHtmlSelect::option():
$arrAttribs = array(
'option.attr' => 'attr'
,'attr' => array('data-value' => 'TESTVAL', 'data-rule-required' => 'true', 'data-msg-required' => 'This option is required')
// ,'option.disable' => 'TEST.OPTDISABLE'
// ,'option.key' => 'data-value'
// ,'option.label' => 'TEST.OPTLABEL'
// ,'option.text' => 'TEST.OPTTEXT'
);
$objOption = JHtml::_('select.option', (string) $option['value'],
JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)),
$arrAttribs
);
Unfortunately I can't seem to get the desired output. As soon as I uncomment any other optional argument JHtmlSelect::option() reports this error:
Undefined property: stdClass::$value in \layouts\joomla\form\field\text.php on line 86
Anybody who may explain the correct way to pass optional arguments that make the target method render list options with custom attributes as described? And mabe you can explain in more detail the concept of this override as the function doc alone don't suffice and there is no example use case within the Joomla code base.