Skip to content

Commit

Permalink
Don't modife the existingTags prop directly (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMordred committed Sep 28, 2020
1 parent b4d759f commit 4e62677
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/VoerroTagsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ export default {
},
created () {
this.typeaheadTags = this.existingTags;
this.tagsFromValue();
if (this.typeaheadAlwaysShow) {
Expand Down Expand Up @@ -304,6 +306,12 @@ export default {
}
},
existingTags(newVal) {
this.typeaheadTags.splice();
this.typeaheadTags = newVal;
},
tags() {
// Updating the hidden input
this.hiddenInput = JSON.stringify(this.tags);
Expand Down Expand Up @@ -357,7 +365,7 @@ export default {
if (!this.onlyExistingTags && text.length && this.validate(text)) {
this.input = '';
// Determine if the inputted tag exists in the existingTags
// Determine if the inputted tag exists in the typeagedTags
// array
let newTag = {
key: '',
Expand All @@ -370,7 +378,7 @@ export default {
: newTag.value.toLowerCase()
);
for (let tag of this.existingTags) {
for (let tag of this.typeaheadTags) {
const compareable = this.escapeRegExp(
this.caseSensitiveTags
? tag.value
Expand Down Expand Up @@ -509,13 +517,13 @@ export default {
// AJAX search
if (this.typeaheadUrl.length > 0) {
this.existingTags.splice();
this.typeaheadTags.splice();
const xhttp = new XMLHttpRequest();
const that = this;
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
that.existingTags = JSON.parse(xhttp.responseText);
that.typeaheadTags = JSON.parse(xhttp.responseText);
that.doSearch(searchQuery);
}
Expand All @@ -541,7 +549,7 @@ export default {
* @return void
*/
doSearch(searchQuery) {
for (let tag of this.existingTags) {
for (let tag of this.typeaheadTags) {
const compareable = this.caseSensitiveTags
? tag.value
: tag.value.toLowerCase();
Expand Down

0 comments on commit 4e62677

Please sign in to comment.