Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Creating new predefined drop-down select option-types

Open webangon opened this issue 11 years ago • 4 comments

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. untitled But the values are not saving. Thanks

webangon avatar Aug 02 '15 11:08 webangon

http://stackoverflow.com/questions/3518002

ghost avatar Aug 02 '15 11:08 ghost

But this is not saving the selected value.

webangon avatar Aug 02 '15 11:08 webangon

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

ghost avatar Aug 02 '15 11:08 ghost

http://manual.unyson.io/en/latest/options/create-option-type.html#content

ghost avatar Aug 02 '15 12:08 ghost