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