Skip to content
This repository
Browse code

[custom select] Filter placeholders out of the list of selected items…

… - Fixes: #4061
  • Loading branch information...
commit fd959b9829b9da5e71044e2934e80bf6756112d1 1 parent 4707068
Gabriel "_|Nix|_" Schulhof authored June 22, 2012

Showing 1 changed file with 12 additions and 5 deletions. Show diff stats Hide diff stats

  1. 17  js/jquery.mobile.forms.select.custom.js
17  js/jquery.mobile.forms.select.custom.js
@@ -266,19 +266,22 @@ define( [
266 266
 				return options.text() !== list.text();
267 267
 			},
268 268
 
  269
+			selected: function() {
  270
+				return this._selectOptions().filter( ":selected:not(:jqmData(placeholder='true'))" );
  271
+			},
  272
+
269 273
 			refresh: function( forceRebuild , foo ){
270 274
 				var self = this,
271 275
 				select = this.element,
272 276
 				isMultiple = this.isMultiple,
273  
-				options = this._selectOptions(),
274  
-				selected = this.selected(),
275  
-				// return an array of all selected index's
276  
-				indicies = this.selectedIndices();
  277
+				indices;
277 278
 
278 279
 				if (  forceRebuild || this._isRebuildRequired() ) {
279 280
 					self._buildList();
280 281
 				}
281 282
 
  283
+				indicies = this.selectedIndices();
  284
+
282 285
 				self.setButtonText();
283 286
 				self.setButtonCount();
284 287
 
@@ -461,6 +464,7 @@ define( [
461 464
 					dataIndexAttr = dataPrefix + 'option-index',
462 465
 					dataIconAttr = dataPrefix + 'icon',
463 466
 					dataRoleAttr = dataPrefix + 'role',
  467
+					dataPlaceholderAttr = dataPrefix + 'placeholder',
464 468
 					fragment = document.createDocumentFragment(),
465 469
 					isPlaceholderItem = false,
466 470
 					optGroup;
@@ -493,6 +497,9 @@ define( [
493 497
 					if (needPlaceholder && (!option.getAttribute( "value" ) || text.length == 0 || $option.jqmData( "placeholder" ))) {
494 498
 						needPlaceholder = false;
495 499
 						isPlaceholderItem = true;
  500
+
  501
+						// If we have identified a placeholder, mark it retroactively in the select as well
  502
+						option.setAttribute( dataPlaceholderAttr, true );
496 503
 						if ( o.hidePlaceholderMenuItems ) {
497 504
 							classes.push( "ui-selectmenu-placeholder" );
498 505
 						}
@@ -509,7 +516,7 @@ define( [
509 516
 					item.setAttribute(dataIndexAttr,i);
510 517
 					item.setAttribute(dataIconAttr,dataIcon);
511 518
 					if ( isPlaceholderItem ) {
512  
-						item.setAttribute( dataPrefix + "placeholder", true );
  519
+						item.setAttribute( dataPlaceholderAttr, true );
513 520
 					}
514 521
 					item.className = classes.join(" ");
515 522
 					item.setAttribute('role','option');

0 notes on commit fd959b9

Please sign in to comment.
Something went wrong with that request. Please try again.