0

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.

4
  • Do you want to make it work with multiple values? Commented May 24, 2017 at 8:03
  • Yes, i want to make it work with the selectpicker - i named it "Multiple values" Commented May 24, 2017 at 8:04
  • Ok, gimme a minute Commented May 24, 2017 at 8:06
  • And here it goes: stackoverflow.com/a/44152825/1681154 Commented May 24, 2017 at 8:22

3 Answers 3

1

First you need to set value on your options:

        <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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks - how can i set the "All" option to be the default? when load - all the events disappears
By using standard HTML - selected attribute, like so - <option value='all' selected>All zones</option>.
Thanks - i get an error "Uncaught TypeError: Cannot read property 'includes' of null" - i guess the selectedValues returns null
@RoyBarOn can you provide the Plunk where you are getting this? Also let me know the browser type and version you are using.
I'm getting the error in the Development - not on plunker - i guess it's caused by selectedValues.includes() returns null while unchecking all
|
1

Ok, After observing your code, I found multiple things that you missed.

  1. Multiple Selector wasn't provided with values attribute
  2. It's <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

1 Comment

Thanks - i get an error once the $('#multi_zones').val().indexOf(e) is null, any idea how can i fix it?
0

Try this

eventRender: function(event, element) {
   var zone_class = event.className.toString();

   return ['all', zone_class].some(e => $('#zones_filter').val().indexOf(e) >= 0)
},

1 Comment

Thanks - I've tried it with the selectpicker but it doesn't worked, i changed it to eventRender: function(event, element) { var zone_class = event.className.toString(); return ['all', zone_class].some(e => $('#zones').val().indexOf(e) >= 0) }, }); $('#zones').on('change',function(){ $('#calendar').fullCalendar('rerenderEvents'); })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.