The yii2 drop-down box provides the search function and the yii2 drop-down box search function. The yii2 drop-down box provides the search function. the yii2 drop-down box search function is simple and small, but it is quite easy to use. Share it with others to make development more efficient and happy. the yii2 drop-down box includes the search function and the yii2 drop-down box search function.
Simple and small functions, but it is quite easy to use. Share it to let more people have a faster development efficiency, happy and happy programming.
Author: White Wolf Source: http://www.manks.top/yii2_dropdown_search.html this article copyright to the author, welcome to reprint, but without the author's consent must retain this paragraph of the statement, and in the article page clearly given the original connection, otherwise, you are entitled to pursue legal liability.
If you have not used composer, you can get out of it. in my tutorials, composer is absolutely magical. Let's talk about this point. let's use composer for installation.
Don't worry. let's first look at what it looks like, or you're not in the mood to see it. For more information, see.
What are you not interested in? Continue to read it. after reading the operation, you can find out where it is.
You may feel very handsome. of course, there are far more than what you can do. it is also very helpful to you.
Okay, so hurry up and install it. Otherwise, the conversation will be endless.
Composer require kartik-v/yii2-widget-select2 "@ dev" # special note, because the dev version installed here, that is, the development version, the unstable version, if your project is hosted by git, after the composer is installed, remember to delete the \ vendor \ kartik-v \ yii2-widget-select2 directory. git file, or you cannot submit it.
It will take about five minutes for him to complete the installation. then we can start using it like below.
// If your form is ActiveForm, use
Use kartik \ select2 \ Select2; // $ data is a key-value pair array. key-value, all $ data declared below are key-value pairs, take this array as an example $ data = [2 => 'widget ', 3 => 'dropdownlist', 4 => 'ii2']; echo $ form-> field ($ model, 'title')-> widget (Select2: classname (), ['data' => $ data, 'options' => ['holder' => 'select... '],]);
// If your form is not ActiveForm, you can refer to the following
Use kartik \ select2 \ Select2; echo Select2: widget (['name' => 'title', 'data' => $ data, 'options' => ['holder' => 'select... ']);
When updating data generated by non-ActiveFomr, you need to select it by default. you can add the value.
Use kartik \ select2 \ Select2; echo Select2: widget (['name' => 'title', 'value' => 2, 'data' => $ data, 'options' => ['holder' => 'select... ']); # What if your form is generated by ActiveForm, but the field is often not a table field? For example, you only need to specify $ model-> title = ['title1', 'title2 '];
Continue reading
Simple and small functions, but it is quite easy to use. Share it so that more people can develop more efficiently and be happy...