Answer the question
In order to leave comments, you need to log in
How to customize yii2-selectize-widget widget?
I use a widget yii2-selectize-widget
to visually select publication tags. It is necessary for me that already selected tags are displayed in the widget field by default and also a drop-down list with available tags appears when clicking on the form. The form:
echo $form->field($model, 'tags')->widget(Selectize::className(), [
'clientOptions' => [
'labelField' => 'name',
'valueField' => 'id',
'plugins' => ['remove_button'],
'persist' => true,
'create' => false,
'options' => ,
]
]);
options
array of values available for selection gets into. But how to make the necessary values selected by default so that when editing an article, you do not select them every time anew?
Answer the question
In order to leave comments, you need to log in
I like demos.krajee.com/widget-details/select2 better based on https://select2.github.io, at least there are docks there.
And your task is solved somehow like this:
use kartik\widgets\Select2;
$data = [
"red" => "red",
"green" => "green",
"blue" => "blue",
"orange" => "orange",
];
// Tagging support Multiple
$model->colorTags = ['red', 'green']; // initial value
echo $form->field($model, 'colorTags')->widget(Select2::classname(), [
'data' => $data,
'options' => ['placeholder' => 'Select a color ...', 'multiple' => true],
'pluginOptions' => [
'tags' => true,
'tokenSeparators' => [',', ' '],
'maximumInputLength' => 10
],
])->label('Tag Multiple');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question