Always add custom tag on top of list when no tags matches.
--- a/src_js/iconolab-bundle/src/components/tagform/Typeahead.vue Tue Mar 14 16:33:12 2017 +0100
+++ b/src_js/iconolab-bundle/src/components/tagform/Typeahead.vue Tue Mar 14 16:49:55 2017 +0100
@@ -27,6 +27,7 @@
<script>
import typeahead from 'vue-typeahead'
+ import _ from 'lodash'
var autoCompletePath = "https://lookup.dbpedia.org/api/search/PrefixSearch?MaxHits=5";
var wikipediaPath = "https://fr.wikipedia.org/w/api.php"
@@ -148,15 +149,18 @@
responseData = this.prepareWikipediaResponse(responseData);
}
- // When no tags found, create a custom tag
- if (Array.isArray(responseData) && !responseData.length) {
- return [{
- tag_label: this.query,
- tag_link: this.query,
- accuracy: 0,
- relevancy: 0
- }];
+ var exactMatch = _.find(responseData, (tag) => tag.tag_label === _.upperFirst(this.query));
+ if (!exactMatch) {
+ if (Array.isArray(responseData)) {
+ responseData.unshift({
+ tag_label: this.query,
+ tag_link: this.query,
+ accuracy: 0,
+ relevancy: 0
+ });
+ }
}
+
return responseData;
},