Joomla 3.2 Grouped list Custom field list does not matter SELECTED

I am trying to create a custom field form for a template parameter for Joomla 3 by following the instructions on this page. Creating a custom form field type

Here are my codes:

class JFormFieldMy extends JFormField { protected $type = 'my'; public function getInput() { return '<select id="'.$this->id.'" name="'.$this->name.'">'. '<optgroup label="First">'. '<option value="1">One</option>'. '<option value="2">Two</option>'. '<option value="3">Three</option>'. '</optgroup>'. '<optgroup label="Second">'. '<option value="4">Four</option>'. '<option value="5">Five</option>'. '<option value="6">Six</option>'. '</optgroup>'. '</select>'; } } 

It works well, the value is saved, but the selected value does not have the selected value = "selected", so the option "One" is always displayed in the drop-down list, when I select / the actual value is "Two",

I read this solution: Joomla 2.5 Custom Field List is not selected on the display , but for the general list type, not for the grouped list that I wanted.

Can anybody help me? thanks

+1
source share
1 answer

You do not set the selected list item:

 <option value="the_value" selected>....</option> 

Another approach: instead of deriving your class from JFormField you should get it from the abstract JHtmlList class (you will find it at libraries/cms/html/list.php ) You can start taking libraries/cms/form/field/limitbox.php as an example .

0
source

Source: https://habr.com/ru/post/1434390/


All Articles