php - Update hidden field using Autocomplete in Yii2 -
I'm working on an auto-complete widget. So far this is my code.
My view:
& lt ;? Php $ data = Company :: find () - & gt; Select (['name as value', 'name as name', 'c_id as id']) - & gt; AsArray () - & gt; all (); Copy autocomplete :: widget (['name' = & gt; 'company', 'id' => ddd ',' client option '= & gt; [' source '= & gt; $ data, 'Autofill' = & gt;, 'Minnamp' = & gt; '4', 'Selection' => New JS Express ("Function (Event, UI) {console.log (ui); $ ('# User -company '). Val (ui.item) .id);} ")],]); ? & Gt; & Lt ;? = Html :: ActiveHideInput ($ Model, 'Company')? & Gt; While selecting an option the autocomplete options are updating in my text area but not updating the hidden area.
How do I get to update a hidden area, when an option is selected?
You can use these properties:
-
Labels - -
value - after the selection, jumps to the input field, -
id < / Code> - For example: & lt; Additional parameters for input type = "hidden" id = "user_company" name = "user_company" value = "qwe" & gt; & Lt ;? Php use yii \ web \ jsExpression; Copy autocomplete :: widget (['name' = & gt; 'company', 'id' = & gt; 'ddd', 'client option' => ['source' = & gt; [[label '= & Gt;' color1 ',' value '= & gt;' key1 ',' id '=>' c_id1 '], [' label '= & gt;' color 2 ',' value '= & Gt; 'key2', 'id' = & gt; 'C_id2']], 'autofill' = & gt; true, 'minnumber' => gt; '0', 'select' => New JS Express ("Function (Event, UI) {console.log (ui); $ ('#user_company'). Val (ui.item.id);}")],]);; & Gt;
Comments
Post a Comment