Yii2 add class or function to list form field

I need to add class and function to dropdown in active Yii2 form, here is the code:

<?= $form->field($model, 'tipocontratto')->dropDownList(['RES' => 'Residenziale', 'BUS' => 'Business'], ['prompt'=>'Seleziona...'],['maxlenght'=> true]); ?>

      

code> I need to specify a class for a field as well as a javascript function. In a normal textbox, I do like this: field($model, 'cogn_ragsoc')->textInput(['maxlength' => true,'class'=>'form-control formtesto','onfocus'=>'test()']) ?>

and it works fine, but in the dropdown it is not How can I do this?

+3


source to share


2 answers


This works great.



<?= $form->field($model, 'tipocontratto')->dropDownList(['RES' => 'Residenziale', 'BUS' => 'Business'], ['prompt'=>'Seleziona...','class'=>'yourclass','onchange'=>'function()']); ?>

      

+5


source


try adding parameters with a class like ::



<?= $form->field($model, 'tipocontratto')->dropDownList(['RES' => 'Residenziale', 'BUS' => 'Business'], 
['prompt'=>'Seleziona...'],['maxlenght'=> true], 
[options=> ['class' => 'yuorClass']]); ?>

      

0


source







All Articles