Joomla 3.2分组列表自定义字段列表没有SELECTED值 [英] Joomla 3.2 Grouped List Custom Field List doesn't have SELECTED value
问题描述
我正在尝试按照此页面上的说明为Joomla 3的模板参数创建自定义字段表单 创建自定义表单字段类型
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
这是我的代码:
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>';
}
}
效果很好,可以保存该值,但是所选值不具有selected ="selected"状态,因此当我选择/实际值为"Two"时,下拉列表将始终显示选项'One'
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'
我已阅读此解决方案: Joomla 2.5 Custom在显示中未选择字段列表" ,但这是针对通用列表类型的,不适用于我想要的分组列表.
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>
另一种方法:您应该从抽象类JHtmlList派生它,而不是从JFormField派生您的类(您可以在libraries/cms/html/list.php
上找到它)
您可以开始以libraries/cms/form/field/limitbox.php
为例.
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.
这篇关于Joomla 3.2分组列表自定义字段列表没有SELECTED值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!