Reputation: 987
I'm using selectpicker with fullcalendar, I've created a filter which works well with single values, but I can't make it works with selectpicker...
Here is my plunker
eventRender: function(event, element) {
var zone_class = event.className.toString();
return ['all', zone_class].indexOf($('#zones_filter').val()) >= 0;
},
How can I add multiple values in the return? Thanks.
Upvotes: 0
Views: 1124
Reputation: 3503
First you need to set value
on your option
s:
<select title="Vacances scolaires" id="zones" class="selectpicker" data-width="fit"
multiple="" style="display: none;" name="vacances[]">
<option value='all' selected>All zones</option>
<option data-icon="glyphicon glyphicon-zone-a" value="zone_a">Zone A</option>
<option data-icon="glyphicon glyphicon-zone-b" value="zone_b">Zone B</option>
<option data-icon="glyphicon glyphicon-zone-c" value="zone_c">Zone C</option>
</select>
Then you need to subscribe to your selectpicker
:
$('#zones').on('change',function(){
$('#calendar').fullCalendar('rerenderEvents');
});
And finally you need to check if your selection includes your class or all
:
eventRender: function(event, element) {
const zone_class = event.className.toString();
const selectedValues = $('#zones').val();
return selectedValues.includes('all')
|| selectedValues.includes(zone_class);
}
Check this Plunker.
Upvotes: 1
Reputation: 2472
Ok, After observing your code, I found multiple things that you missed.
<label>
not <lable>
So to begin I added an id="multi_zones"
and values within the options on your Multiple Selector select.
And updated this:
eventRender: function(event, element) {
var zone_class = event.className.toString();
return ['all', zone_class].some(e => $('#multi_zones').val().indexOf(e) >= 0)
},
And updated the caller:
$('#multi_zones').on('change',function(){
$('#calendar').fullCalendar('rerenderEvents');
})
Working plunkr here
Upvotes: 1
Reputation: 6497
Try this
eventRender: function(event, element) {
var zone_class = event.className.toString();
return ['all', zone_class].some(e => $('#zones_filter').val().indexOf(e) >= 0)
},
Upvotes: 0