Commit 5d4cad6a authored by Georgios Ouzounis's avatar Georgios Ouzounis
Browse files

Delete input text when a duplicate topic name is provided

parent 2b3b1588
......@@ -19,11 +19,24 @@ export default Ember.Component.extend({
createTokenEvent: function(event){
var existingTokens = Ember.$(this).tokenfield('getTokens');
var duplicate = false;
Ember.$.each(existingTokens, function(index, token) {
if (token.value === event.attrs.value){
event.preventDefault();
duplicate = true;
return false;
}
return true;
});
// If the provided name for the new token already exists, delete the input text
if(duplicate){
var componentId = Ember.$(this)[0].id;
Ember.$('#' + componentId + " #" + componentId + "-tokenfield")[0].value = "";
}
return !duplicate;
},
actions: {
......
<input type="text" class="form-control" id="{{id}}" placeholder="e.g. topic1, topic2, topic3" onChange={{action "updateTopics"}}>
\ No newline at end of file
<input type="text" class="form-control" id="{{id}}" placeholder="e.g. topic1, topic2, topic3" onChange={{action "updateTopics"}}>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment