mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: Selecting default option without changing HTML markup.
I also filed a bug on Ember.js with details on the error.
This commit is contained in:
parent
5ec77d4be4
commit
dd7b3d313e
1 changed files with 9 additions and 5 deletions
|
@ -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('<select class=\'combobox\'>');
|
||||
if (typeof none === "string") {
|
||||
buffer.push('<option value="">' + I18n.t(none) + "</option>");
|
||||
} else if (typeof none === "object") {
|
||||
|
@ -47,11 +46,10 @@ export default Discourse.View.extend({
|
|||
buffer.push("<option " + selectedText + " value=\"" + val + "\" " + self.buildData(o) + ">" + Handlebars.Utils.escapeExpression(Em.get(o, nameProperty)) + "</option>");
|
||||
});
|
||||
}
|
||||
buffer.push('</select>');
|
||||
},
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue