Skip to content

Commit

Permalink
fixed focus and duplication tag issues
Browse files Browse the repository at this point in the history
refs #5648
- adds default value to refocus in reloadTypeahead method to fix focus issues
- moves tag input clearing call up to avoid duplication.
  • Loading branch information
acburdine committed Aug 11, 2015
1 parent 9376bdf commit f04676e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/client/app/components/gh-tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,15 @@ export default Ember.Component.extend({
}, {
name: 'tags',
source: tags
}).bind('typeahead:selected', Ember.run.bind(this, 'typeaheadAdd'));
}).bind('typeahead:select', Ember.run.bind(this, 'typeaheadAdd'));
},

destroyTypeahead: function () {
this.$('#tag-input').typeahead('destroy');
},

reloadTypeahead: function (refocus) {
refocus = (typeof refocus !== 'undefined') ? refocus : true; // set default refocus value
this.set('isReloading', true);
this.destroyTypeahead();
this.initTypeahead();
Expand All @@ -216,7 +217,7 @@ export default Ember.Component.extend({
},

// Used for typeahead selection
typeaheadAdd: function (obj, datum) {
typeaheadAdd: function (event, datum) {
if (datum) {
// this is needed so two tags with the same name aren't added
this.$('#tag-input').typeahead('val', '');
Expand All @@ -228,9 +229,10 @@ export default Ember.Component.extend({
addTag: function (tagName) {
var tagToAdd, checkTag;

this.$('#tag-input').typeahead('val', '');

// Prevent multiple tags with the same name occuring
if (this.get('currentTags').findBy('name', tagName)) {
this.$('#tag-input').typeahead('val', '');
return;
}

Expand All @@ -247,7 +249,6 @@ export default Ember.Component.extend({
this.set('isDirty', true);
this.set('highlightIndex', null);
this.get('currentTags').pushObject(tagToAdd);
this.$('#tag-input').typeahead('val', '');
},

deleteTag: function (tag) {
Expand Down

0 comments on commit f04676e

Please sign in to comment.