Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 add class or function to dropdownlist form field

i need to add a class and a function to a dropdownlist in Yii2 activeform, here's the code:

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

I need to specify a class for the field and also a javascript function. In normal textfield i make this way: field($model, 'cogn_ragsoc')->textInput(['maxlength' => true,'class'=>'form-control formtesto','onfocus'=>'test()']) ?> andd it works perfectly, but in dropdownlist it doesn't How can i do?

like image 963
piebuo Avatar asked Jul 02 '15 11:07

piebuo


1 Answers

This works perfectly.

<?= $form->field($model, 'tipocontratto')->dropDownList(['RES' => 'Residenziale', 'BUS' => 'Business'], ['prompt'=>'Seleziona...','class'=>'yourclass','onchange'=>'function()']); ?>
like image 198
Akshay Avatar answered Sep 27 '22 18:09

Akshay