简体   繁体   中英

Joomla 3.2 Grouped List Custom Field List doesn't have SELECTED value

I am trying to create a custom field form for template parameter for Joomla 3, by following instruction from 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 good, the value is saved, but the selected value doesn't have the selected="selected" state so the dropdown list will always show the option 'One' when I choose / the actual value is 'Two'

I have read this solution : Joomla 2.5 Custom Field List not SELECTED in display but that's for generic list type not for grouped list I wanted.

Anyone can help me? Thanks

You are not setting the selected element of the list:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM