Skip to content

Commit c130a03

Browse files
committed
Updated the select event so it has a chance to cancel selection by returning false.
1 parent f2865c1 commit c130a03

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

ui/jquery.ui.selectmenu.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,13 @@ $.widget("ui.selectmenu", {
274274
.data('optionClasses', selectOptionData[i].classes || '')
275275
.bind("mouseup.selectmenu", function(event) {
276276
if (self._safemouseup && !self._disabled(event.currentTarget) && !self._disabled($( event.currentTarget ).parents( "ul>li." + self.widgetBaseClass + "-group " )) ) {
277-
var changed = $(this).data('index') != self._selectedIndex();
278-
self.index($(this).data('index'));
279-
self.select(event);
280-
if (changed) {
281-
self.change(event);
277+
var oldIdx = self._selectedIndex(), newIdx = t.data('index');
278+
if (self.select(event, oldIdx, newIdx) !== false) {
279+
var changed = oldIdx != newIdx;
280+
if (changed) {
281+
self.index(t.data('index'));
282+
self.change(event);
283+
}
282284
}
283285
self.close(event, true);
284286
}
@@ -484,12 +486,13 @@ $.widget("ui.selectmenu", {
484486
},
485487

486488
// returns some usefull information, called by callbacks only
487-
_uiHash: function() {
488-
var index = this.index();
489+
_uiHash: function(index) {
490+
var idx = index || this.index();
491+
var opt = $("option", this.element).eq(idx);
489492
return {
490493
index: index,
491-
option: $("option", this.element).get(index),
492-
value: this.element[0].value
494+
option: opt,
495+
value: opt.attr('value')
493496
};
494497
},
495498

@@ -538,9 +541,9 @@ $.widget("ui.selectmenu", {
538541
this._trigger("change", event, this._uiHash());
539542
},
540543

541-
select: function(event) {
544+
select: function(event, oldIdx, newIdx) {
542545
if (this._disabled(event.currentTarget)) { return false; }
543-
this._trigger("select", event, this._uiHash());
546+
return this._trigger("select", event, { oldOpt: this._uiHash(oldIdx), newOpt: this._uiHash(newIdx) });
544547
},
545548

546549
_closeOthers: function(event) {

0 commit comments

Comments
 (0)