Bootstrap-star-rating plugin - Events are being called multiple time

392 Views Asked by At

Am using this Bootstap star rating plugin version v4.0.5 with JQuery 3.1.1. I have initialized the plugin after calling livequery plugin (from this author Brandon Aaron) as my star rating input is added on demand when the DOM is already initialized The whole thing works great with the only exception that events get called so many time. And the number of time they get triggered keeps increasing on the same element when the user interacts with. (See the image below)

Please, any idea on what could be the reason for this? Any fix?

My script:

$('.langLevel').livequery(function() {
  $('#langLevel0').rating({
    step: 1,
    min: 0,
    max: 5,
    size: 'sm',
    theme: 'krajee-fa',
    // clearButton: '',
    captionElement: "",
    showCaptionAsTitle: false,
    starCaptions: {
      1: 'Beginner',
      2: 'Intermediate',
      3: 'Advanced',
      4: 'Proficient',
      5: 'Native'
    },
    starCaptionClasses: {
      1: 'text-danger',
      2: 'text-warning',
      3: 'text-info',
      4: 'text-primary',
      5: 'text-success'
    }
  }).on("rating:clear", function(event) {
    console.info("Your rating is reset");
  }).on("rating:change", function(event, value, caption) {
    console.info("You rated: " + value + " = " + $(caption).text());
  });
}, function() {
  // unmatchFn
  return;
});

Thank you in advance for your assistance

0

There are 0 best solutions below