I've created custom widget by extending jQuery UI's Menu. It's basically needed to work with <select>
HTML element like ui.selectmenu does, but display options in submenus:
$.widget("market.myMenu",$.ui.menu, {
// ...
_attachEvents: function(){
var self = this;
// menu is initially hidden
self.menuWrapper.hide();
self.button.on('click', function(){
if (self.originalSelect.is(':disabled')) {
self.disable();
} else {
self.menuWrapper.toggle();
}
return false;
});
$(document).on('click', function(){
self.menuWrapper.hide();
});
},
//...
}
}
The problem arise when this widget attached to multiple elements like:
someSelect.myMenu();
//...
anotherSelect.myMenu();
The problem is listed in the title and you can see it in _attachEvents()
method:
- when user clicks on
someSelect
it opens as should - then user clicks on
anotherSelect
it also opens someSelect
after step2
should be closed, but it's not.
So how to check for such a case and fix this issue ?
EDIT:
this.originalSelect
is<select>
HTML elementthis.button
is div element. on which selected option text is displayed (basically same thing asui.selectmenu
does);