wbraganca / yii2-dynamicform

It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.
Other
436 stars 439 forks source link

DynamicFormWidget & Kartik Select2 set value #194

Open lexen77 opened 7 years ago

lexen77 commented 7 years ago

Hi, I can not set the value of the select2 when i return id from any function. This Is my code

field($modelAnagrafica, "[{$i}]id_anagrafica_ricerca")->widget(Select2::classname(), [ 'initValueText' => $cognome, 'options'=>[ 'placeholder'=>'---- Seleziona ----', 'onchange'=>'JS: var indice = (this.id).substr(10,3); $.get( "'.Url::toRoute('anagrafica/anagraficajson').'", { id: $(this).val() } ) .done(function(arr) var id_anagrafica=arr[0]["id_anagrafica"]; var cbo="#anagrafica-0-id_cittanascita"; $(cbo).select2("va",id_cittanascita); // this is my select2 } ) ], 'pluginOptions' => [ 'minimumInputLength' => 1, 'ajax' => [ 'url' => $urlAjaxAnagrafica, 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }') ], ], ] ); ?>