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

只愿长相守 提交于 2020-01-23 18:01:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/22660483/joomla-3-2-grouped-list-custom-field-list-doesnt-have-selected-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!