Always add custom tag on top of list when no tags matches.
authorAlexandre Segura <mex.zktk@gmail.com>
Tue, 14 Mar 2017 16:49:55 +0100
changeset 432 597cc594e753
parent 431 39893bc3340a
child 433 616fc1fad25f
Always add custom tag on top of list when no tags matches.
src_js/iconolab-bundle/src/components/tagform/Typeahead.vue
--- 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;
             },