Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Selectmenu: Delay trigger until after the list closes
Browse files Browse the repository at this point in the history
Fixes gh-7076
  • Loading branch information
Gabriel Schulhof committed Mar 14, 2014
1 parent 18f872d commit 828349e
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions js/widgets/forms/select.custom.js
Expand Up @@ -110,6 +110,10 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
},

_handleMenuPageHide: function() {

// After the dialog's done, we may want to trigger change if the value has actually changed
this._delayedTrigger();

// TODO centralize page removal binding / handling in the page plugin.
// Suggestion from @jblas to do refcounting
//
Expand Down Expand Up @@ -243,14 +247,16 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
.toggleClass( "ui-checkbox-off", !option.selected );
}

// trigger change if value changed
if ( self.isMultiple || oldIndex !== newIndex ) {
self.select.trigger( "change" );
// if it's not a multiple select, trigger change after it has finished closing
if ( !self.isMultiple && oldIndex !== newIndex ) {
self._triggerChange = true;
}

// trigger change if it's a multiple select
// hide custom select for single selects only - otherwise focus clicked item
// We need to grab the clicked item the hard way, because the list may have been rebuilt
if ( self.isMultiple ) {
self.select.trigger( "change" );
self.list.find( "li:not(.ui-li-divider)" ).eq( newIndex )
.find( "a" ).first().focus();
}
Expand All @@ -266,7 +272,7 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
this._on( this.menuPage, { pagehide: "_handleMenuPageHide" } );

// Events on the popup
this._on( this.listbox, { popupafterclose: "close" } );
this._on( this.listbox, { popupafterclose: "_popupClosed" } );

// Close button on small overlays
if ( this.isMultiple ) {
Expand All @@ -276,6 +282,18 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
return this;
},

_popupClosed: function() {
this.close();
this._delayedTrigger();
},

_delayedTrigger: function() {
if ( this._triggerChange ) {
this.element.trigger( "change" );
}
this._triggerChange = false;
},

_isRebuildRequired: function() {
var list = this.list.find( "li" ),
options = this._selectOptions().not( ".ui-screen-hidden" );
Expand Down

0 comments on commit 828349e

Please sign in to comment.