Reputation: 1037
So I have this problem where I have a dropdown and then I create it using dropkick.js. (I am just learning dropkick.js so I am now thinking that I misunderstood something.)
The Problem
When I bind an on change event like so
$('.pizza_size').on('change', 'select[name=pizza_size]', function() {
alert(this.value);
});
The alert is called twice.
My initial problem was that the select dropdown was changed dynamically, so the $(".default").dropkick();
didn't apply anymore, so I created this dynamic selector above. (If there is a better way to bind the call dynamically than this please do tell! :D)
Helpful information: (based on some of my debugging)
<select>...</select>
and the one dropkick.js creates with the class=dk_container dk_theme_default
class. So I commented this html to avoid this (in first fiddle), but it still seems to exist 2 select dropdowns!Upvotes: 0
Views: 202
Reputation: 338326
You probably simply should use the documented API of dropkick.
$(function () {
$('.default').dropkick({
change: function () {
alert("You selected " + $(this).val() + " for " + this.id + ".");
}
});
});
Upvotes: 1
Reputation: 2466
I think I found the issue :
Inside your dropkick.js plugin you have select triggered twice. Search for these lines inside your plugin
$select.trigger('change');
$select.val(value).trigger('change');
Comment the first line here
$select.trigger('change'); // comment this line in your dropkick.js file
and try. "The alert is called twice." this will be fixed.
Upvotes: 2