From dd7b3d313e9698fefa26cb3921bd6ce8451428db Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 4 Dec 2014 15:21:47 -0500 Subject: [PATCH] FIX: Selecting default option without changing HTML markup. I also filed a bug on Ember.js with details on the error. --- .../javascripts/discourse/views/combo-box.js.es6 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/views/combo-box.js.es6 b/app/assets/javascripts/discourse/views/combo-box.js.es6 index fe2381243..24d4b2d28 100644 --- a/app/assets/javascripts/discourse/views/combo-box.js.es6 +++ b/app/assets/javascripts/discourse/views/combo-box.js.es6 @@ -7,7 +7,7 @@ @module Discourse **/ export default Discourse.View.extend({ - tagName: 'span', + tagName: 'select', attributeBindings: ['tabindex'], classNames: ['combobox'], valueAttribute: 'id', @@ -27,7 +27,6 @@ export default Discourse.View.extend({ none = this.get('none'); // Add none option if required - buffer.push(''); }, valueChanged: function() { - var $combo = this.$('select'), + var $combo = this.$(), val = this.get('value'); if (val !== undefined && val !== null) { $combo.val(val.toString()); @@ -66,9 +64,15 @@ export default Discourse.View.extend({ }.observes('content.@each'), didInsertElement: function() { - var $elem = this.$('select'), + var $elem = this.$(), self = this; + // Workaround for https://github.com/emberjs/ember.js/issues/9813 + // Can be removed when fixed. Without it, the wrong option is selected + this.$('option').each(function(i, o) { + o.selected = !!$(o).attr('selected'); + }); + $elem.select2({formatResult: this.template, minimumResultsForSearch: 5, width: 'resolve'}); $elem.on("change", function (e) {