Unyson
Unyson copied to clipboard
Creating new predefined drop-down select option-types
Hi ,This is an awesome framework . However i like to create a select dropdown menu. It renders correctly but the option values are not saving.
My code to do that
protected function _render( $id, $option, $data ) {
$option['attr']['value'] = (string) $data['value'];
$myArray2 = array('c'=>'Cat','m'=>'Mat','f'=>'Fat','h'=>'Hat');
echo'<select name="Words">';
foreach($myArray2 as $let=>$word){
echo'<option value="'.$let.'">'.$word.'</option>';
}
echo'</select>';
}
This renders exactly what i want.
But the values are not saving. Thanks
http://stackoverflow.com/questions/3518002
But this is not saving the selected value.
Also <select name="Words">, you must use $option['attr']['name'], and better to use $option['attr'], and not echo but return, so
$html = '<select '. fw_attr_to_html($option['attr']) .'>';
// ...
return $html;
inspect predefined option-types
http://manual.unyson.io/en/latest/options/create-option-type.html#content