From d69b7827371747ab91f75fca32908985530f72fc Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 15 Dec 2016 10:40:11 -0500 Subject: [PATCH] FIX: Editing tags was double rendering --- .../discourse/components/tag-chooser.js.es6 | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/discourse/components/tag-chooser.js.es6 b/app/assets/javascripts/discourse/components/tag-chooser.js.es6 index a8fa6bc1835..578fb9a16d1 100644 --- a/app/assets/javascripts/discourse/components/tag-chooser.js.es6 +++ b/app/assets/javascripts/discourse/components/tag-chooser.js.es6 @@ -8,10 +8,17 @@ export default Ember.TextField.extend({ classNameBindings: [':tag-chooser'], attributeBindings: ['tabIndex', 'placeholderKey', 'categoryId'], - _initValue: function() { + init() { + this._super(); const tags = this.get('tags') || []; this.set('value', tags.join(", ")); - }.on('init'), + + if (this.get('allowCreate') !== false) { + this.set('allowCreate', this.site.get('can_create_tag')); + } + + this.set('termMatchesForbidden', false); + }, _valueChanged: function() { const tags = this.get('value').split(',').map(v => v.trim()).reject(v => v.length === 0).uniq(); @@ -32,18 +39,13 @@ export default Ember.TextField.extend({ } }.observes('tags'), - _initializeTags: function() { - const site = this.site, - self = this, - filterRegexp = new RegExp(this.site.tags_filter_regexp, "g"); + didInsertElement() { + this._super(); - var limit = this.siteSettings.max_tags_per_topic; + const self = this; + const filterRegexp = new RegExp(this.site.tags_filter_regexp, "g"); - if (this.get('allowCreate') !== false) { - this.set('allowCreate', site.get('can_create_tag')); - } - - this.set('termMatchesForbidden', false); + let limit = this.siteSettings.max_tags_per_topic; if (this.get('unlimitedTagCount')) { limit = null; @@ -77,7 +79,7 @@ export default Ember.TextField.extend({ callback(data); }, - createSearchChoice: function(term, data) { + createSearchChoice(term, data) { term = term.replace(filterRegexp, '').trim().toLowerCase(); // No empty terms, make sure the user has permission to create the tag @@ -89,14 +91,14 @@ export default Ember.TextField.extend({ return { id: term, text: term }; } }, - createSearchChoicePosition: function(list, item) { + createSearchChoicePosition(list, item) { // Search term goes on the bottom list.push(item); }, - formatSelection: function (data) { + formatSelection(data) { return data ? renderTag(this.text(data)) : undefined; }, - formatSelectionCssClass: function(){ + formatSelectionCssClass() { return "discourse-tag-select2"; }, formatResult: formatTag, @@ -127,10 +129,11 @@ export default Ember.TextField.extend({ } }, }); - }.on('didInsertElement'), + }, - _destroyTags: function() { + willDestroyElement() { + this._super(); this.$().select2('destroy'); - }.on('willDestroyElement') + } });