The question is simple. I want to add different data-attributes to each selection option so that Bootstrap will load different data according to which option was selected.
How should I go with it? Adding options to field()->dropDownList() will only add the options to list elements container.
I got the result please try this one may be solve problem i got batter solution
$listOption = [
[156] => 'Option1',
[157] => 'Option2',
[158] => 'Option3',
[162] => 'Option4'
];
$optionDataAttributes = [
[156] => [
['data-width'] => 10,
['data-height'] => 10
],
[157] => [
['data-width'] => 11,
['data-height'] => 11
],
[158] => [
['data-width'] => 12,
['data-height'] => 12
],
[162] => [
['data-width'] => 13,
['data-height'] => 13
],
];
echo $form->field($model, 'field_name')->dropDownList($listOption ,
[
'options' => $optionDataAttributes,
'prompt' => 'Select Custom Package',
'class' => 'form-control input-sm',
'id' => 'package_select_id'
])->label(false);
Try with options
echo $form->field($model, 'name')->dropDownList( $listData,
['options'=>['class' => 'yourClass',
'style' => 'yourStyle',
'yourAtt'=> 'yourattribute']]);
or try
echo $form->field($model, 'name')->dropDownList( $listData,
['data-target'=> 'yourValue',
'data-toggle' => ' your2value']);
for items you can use
echo $form->field($model, 'name')->dropDownList( $listData,
['options'=>[
'value1' => ['data-target' => 'yourAtt']]);,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With