Reputation: 2786
I've this code
echo Select2::widget([
'model' => implode(', ', ["ROME","NY"]),
'name' => 'city',
'options' => [
'id'=>'city',
'placeholder' => 'select a city ...',
'class'=>'form-control'
],
'pluginOptions' => [
'tags' => $city,
'maximumInputLength' => 4,
],
]);
my js file
$('#city').on('change',function(x){
$.ajax({
url: '?r=markermap/setmarkerajax',
type: 'POST',
data: {'city':x.val},
success: function(res){
setMarkers(res);
}
});
});
Plugin works when i select a city. Into controller i store into session values and want when reload or came back into page set again old value. With this plugin how can do? Into page i read that support $model , but i've session and not model object.
Upvotes: 0
Views: 3468
Reputation: 4313
<?php
$data = ["red", "green", "white", "black", "purple", "cyan"];
// without model
echo Select2::widget([
'name' => 'category',
'value' => "green,red", // value to initialize
'options'=> [],
'pluginOptions' => [
'tags' => $data,
'maximumInputLength' => 4,
],
]);
?>
Upvotes: 4