Yii2: Create a dropdownlist with an icon at the end of the field

How can I create a dropdown in the yii2 form field which has a plus icon at the end of the drop-down field like a calendar icon in the date field?

Another requirement, I need a searchable dropdown in yii2, which can search value does not exist in DB, and if the searched value does not exist in the database it can save into DB as a new entry. Is it possible in yii2?

I suggest you start here and keep experimenting

There is Select2 and Selectize for that

Hi,
Thank you for your reply. Yes, I am familiar with both these cases. But My Question is how can use this tag for the icon in the yii2 form field

Here is my code

<?= $form->field($model, 'first_name', [ 'labelOptions'=>['class'=>'text-dark-blue text12 required-star'] , 'wrapperOptions'=>['class'=>'col-sm-12 offset-sm-0 p-0 '] , 'options'=>['class' => ''] ]); ?>

And also I am familiar with the searchable dropdown in select2 and I already implemented it. But I am not able to save the data in the seach field for searchable dropdown into DB if that is not present in the DB. Here is my code. Search is possible in this drop-down and also can save data into Db when we select a value from the drop-down list. But failed to save the data that was typed in the search field and did not exist in the DB. Kindly check and Update.

<?=$form->field ( $model, 'state' , ['options'=>['class'=>'col mb-3'] ,'labelOptions'=>['class'=>''] ,'wrapperOptions'=>['class'=>'col-sm-12 offset-sm-0 p-0'] ])->widget(Select2::classname(), [ 'items' => ArrayHelper::map(State::getState(),'id','state'), 'options' => ['id' => 'state_id_list', 'class' => 'form-control col-md-12 width-100 state-search','prompt' =>'- Select -'], ]);?>

Never done that before so, I have no idea

See Update Tags with Select2 Multiple - How Do I... - Select2

Thank You for your reply.Let me try

1 Like