Over my fullcalendar I have a few checkboxes, which I want to be react like a filter. In short: I want to filter for one, all, three, two (multiple)... and so on.
I came this far, that I can select one Checkbox, and it's return the right Events, but it's not working for two ore more checkboxes, of course. But I don't know, how to do this! My Javascript skill is not so good.
I fetch the Events with a Json File, which I created with Ruby on Rails 4 in the Model. But I don't want to split this Json. So I searching for a full Javascript version.
I think, the code will better show, what I mean.
Html:
<input id="hamburg" class="event_filter_box" name="event_filter_select" type="checkbox" value="Hamburg">Hamburg</input>
<input id="schleswig-holstein" class="event_filter_box" name="event_filter_select" type="checkbox" value="Schleswig-Holstein">Schleswig-Holstein</input>
<input id="party" class="event_filter_box" name="event_filter_select" type="checkbox" value="Party">Party</input>
<input id="concert" class="event_filter_box" name="event_filter_select" type="checkbox" value="Concert">Concert</input>
<input id="festival" class="event_filter_box" name="event_filter_select" type="checkbox" value="Festival">Festival</input>
<div id="calendar"></div>
Javascript:
$(document).ready(function() {
$('input[class=event_filter_box]').change(function() {
$('#calendar').fullCalendar('rerenderEvents');
});
});
$("#calendar").fullCalendar({
events: [
{
title: 'Party Event in Hamburg',
start: '2015-11-11',
address_city: 'Hamburg',
kind: 'Party',
},
{
title: 'Conzert Event in Hamburg',
start: '2015-11-10',
address_city: 'Hamburg',
kind: 'Concert',
},
{
title: 'Festival Event in Schleswig-Holstein',
start: '2015-11-08',
end: '2015-11-12',
address_city: 'Schleswig-Holstein',
kind: 'Festival',
},
],
defaultView: "basicWeek",
eventRender: function eventRender( event, element, view ) {
if ($('input[id=hamburg]').is(':checked')) {
return ['all', event.address_city].indexOf($('#hamburg').val()) >= 0
} else if ($('input[id=schleswig-holstein]').is(':checked')) {
return ['all', event.address_city].indexOf($('#schleswig-holstein').val()) >= 0
} else if ($('input[id=party]').is(':checked')) {
return ['all', event.kind].indexOf($('#party').val()) >= 0
} else if ($('input[id=concert]').is(':checked')) {
return ['all', event.kind].indexOf($('#concert').val()) >= 0
} else if ($('input[id=festival]').is(':checked')) {
return ['all', event.kind].indexOf($('#festival').val()) >= 0
}
},
});
codepen
How has the Javascript to be, for a multiple Select? Thank's before =)