This commit is contained in:
James Cole
2020-10-29 14:42:24 +01:00
parent b75c221626
commit 1ed71ea742
5 changed files with 21 additions and 32 deletions

View File

@@ -110,20 +110,7 @@ export default {
aSyncFunction: function (query, done) {
axios.get(this.categoryAutoCompleteURI + query)
.then(res => {
// loop over data
let escapedData = [];
let current;
for (const key in res.data) {
if (res.data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
current = res.data[key];
//current.name_html = res.data[key].name;
//current.name = this.escapeHtml(res.data[key].name);
//current.name = res.data[key].name;
escapedData.push(current);
}
}
done(escapedData);
done(res.data);
})
.catch(err => {
// any error handler

View File

@@ -53,7 +53,15 @@
:target="target"
item-key="description"
v-on:input="selectedItem"
></typeahead>
>
<template slot="item" slot-scope="props">
<li v-for="(item, index) in props.items" :class="{active:props.activeIndex===index}">
<a role="button" @click="props.select(item)">
<span v-html="betterHighlight(item)"></span>
</a>
</li>
</template>
</typeahead>
<ul v-for="error in this.error" class="list-unstyled">
<li class="text-danger">{{ error }}</li>
</ul>
@@ -83,23 +91,17 @@ export default {
aSyncFunction: function (query, done) {
axios.get(this.descriptionAutoCompleteURI + query)
.then(res => {
// loop over data
let escapedData = [];
let current;
for (const key in res.data) {
if (res.data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
current = res.data[key];
current.description = this.escapeHtml(res.data[key].description)
escapedData.push(current);
}
}
done(escapedData);
done(res.data);
})
.catch(err => {
// any error handler
})
},
betterHighlight: function (item) {
var inputValue = this.$refs.descr.value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
var escapedName = this.escapeHtml(item.description);
return escapedName.replace(new RegExp(("" + inputValue), 'i'), '<b>$&</b>');
},
escapeHtml: function (string) {
let entityMap = {