Answer the question
In order to leave comments, you need to log in
Pass value to Select2?
There is on the Select2 page, in data I pass an array with id, text (this is how select2 accepts).
But for "templateResult" I want to pass one more parameter to the array, but then select2 does not display the array correctly due to the fact that not 2 values were passed, but already id, text, myParam. How can this be rewritten correctly?
Answer the question
In order to leave comments, you need to log in
A little wrong. In order to set additional parameters for the select options, they need to be placed in the widget options:
echo Select2::widget([
'name' => 'my-select2',
'data' => [1 => 'One', 2 => 'Two'],
'options' => [
'placeholder' => 'Select a number ...',
'options' => [
2 => ['disabled' => true],
]
],
]);
<select>
<option value="1">One</option>
<option value="2" disabled="disabled">Two</option>
</select>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question