#1906 serach form autocmplete multi terms
This commit is contained in:
@ -24,7 +24,7 @@ export default {
|
||||
...mapState({
|
||||
canSearch: state => state.User.canSearch,
|
||||
keys: state => state.Search.keys,
|
||||
term: state => state.Search.term,
|
||||
terms: state => state.Search.terms,
|
||||
filters: state => state.Search.filters
|
||||
}),
|
||||
displayform(){
|
||||
@ -54,7 +54,7 @@ export default {
|
||||
// var urlParamsKeys = urlParams.keys()
|
||||
const params = {
|
||||
keys: this.keys,
|
||||
term: this.term,
|
||||
terms: this.terms, //JSON.stringify(this.terms),
|
||||
filters: this.filters
|
||||
}
|
||||
console.log('Search getSearchForm params', params)
|
||||
|
@ -15,7 +15,7 @@ export default {
|
||||
return {
|
||||
template: null,
|
||||
typed: null,
|
||||
autocomplete: null,
|
||||
autocomplete: [],
|
||||
slimFilters: [],
|
||||
$input: null
|
||||
// basePath: drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix
|
||||
@ -24,7 +24,7 @@ export default {
|
||||
computed: {
|
||||
...mapState({
|
||||
keys: state => state.Search.keys,
|
||||
term: state => state.Search.term,
|
||||
terms: state => state.Search.terms,
|
||||
filters: state => state.Search.filters
|
||||
})
|
||||
},
|
||||
@ -51,26 +51,44 @@ export default {
|
||||
// push router
|
||||
this.$router.push({name:'base', query:{
|
||||
keys:this.typed,
|
||||
term:this.autocomplete,
|
||||
// terms:this.autocomplete.join(','),
|
||||
terms: JSON.stringify(this.autocomplete),
|
||||
filters:filters.join(',')
|
||||
}})
|
||||
// this.$router.push({
|
||||
// path:`${this.basePath}/base`,
|
||||
// query:{keys:this.typed,term:this.autocomplete}
|
||||
// })
|
||||
},
|
||||
onAutoCompleteSelect(event, ui){
|
||||
event.preventDefault();
|
||||
console.log('autoCompleteSelect', event, ui)
|
||||
this.typed = ui.item.label
|
||||
// we have to wait for typed watch to reset autocomplete before setting it
|
||||
setTimeout(function(){
|
||||
console.log('update autocomplete value after settimeout')
|
||||
this.autocomplete = ui.item.value
|
||||
if (this.typed !== this.keys || this.autocomplete !== this.term) {
|
||||
this.submit()
|
||||
console.log('autoCompleteSelect begining', this.typed, event, ui)
|
||||
// split typed into tag list
|
||||
var tag_list = this.typed.split(', ')
|
||||
console.log('tag_list', tag_list)
|
||||
// remove the last item as it is the first letters of autocomplete (like ma for marbre)
|
||||
tag_list.pop()
|
||||
// add in typed the label
|
||||
tag_list.push(ui.item.label)
|
||||
|
||||
this.typed = tag_list.join(', ') + ', '
|
||||
|
||||
// check if item is not already in autocmplete
|
||||
let add = true
|
||||
this.autocomplete.forEach( (term) => {
|
||||
if (term.value == ui.item.value) {
|
||||
add = false
|
||||
return
|
||||
}
|
||||
}.bind(this), 1)
|
||||
})
|
||||
if (add) {
|
||||
this.autocomplete.push(ui.item)
|
||||
}
|
||||
// we have to wait for typed watch to reset autocomplete before setting it
|
||||
// setTimeout(function(){
|
||||
// console.log('update autocomplete value after settimeout')
|
||||
// this.autocomplete.push(ui.item)
|
||||
// if (this.typed !== this.keys || this.autocomplete !== this.term) {
|
||||
// this.submit()
|
||||
// }
|
||||
// }.bind(this), 1)
|
||||
console.log('autoCompleteSelect end : this.autocomplete', this.autocomplete)
|
||||
|
||||
},
|
||||
onSelectFiltersChange(index, info){
|
||||
@ -105,22 +123,34 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
typed(n, o){
|
||||
console.log('typed changed', o, n)
|
||||
// is changed also when autocomplete change it ...
|
||||
this.autocomplete = null
|
||||
},
|
||||
keys(n, o){
|
||||
console.log('keys changed', o, n)
|
||||
this.typed = n
|
||||
},
|
||||
term(n, o){
|
||||
console.log('autocomplete changed', o, n)
|
||||
this.autocomplete = n
|
||||
console.log('watch typed changed o:' + o + ' n:' +n)
|
||||
// todo remove terms from autocomplete if removed from typed
|
||||
const r = /,\s?$/
|
||||
let tag_list = n.replace(r,'').split(', ')
|
||||
console.log('watch typed tag_list', tag_list)
|
||||
console.log('watch typed autocomplete before', this.autocomplete)
|
||||
this.autocomplete.forEach( (term,index,array) => {
|
||||
console.log("watch typed autocomplete term", term, index, array)
|
||||
if (tag_list.indexOf(term.label) < 0) {
|
||||
this.autocomplete.splice(index,1)
|
||||
}
|
||||
});
|
||||
console.log('watch typed autocomplete after', this.autocomplete)
|
||||
}
|
||||
// keys(n, o){
|
||||
// console.log('watch keys changed', o, n)
|
||||
// this.typed = n
|
||||
// },
|
||||
// terms(n, o){
|
||||
// // if term change from store
|
||||
// console.log('watch terms changed', o, n)
|
||||
// this.autocomplete = n
|
||||
// }
|
||||
},
|
||||
created() {
|
||||
// fill component values with store values in case of direct page loading
|
||||
this.typed = this.keys
|
||||
this.autocomplete = this.term
|
||||
this.autocomplete = this.terms
|
||||
},
|
||||
mounted(){
|
||||
// console.log('SearchForm mounted')
|
||||
|
@ -73,10 +73,12 @@ export default {
|
||||
this.pagetitle = 'Base'
|
||||
}
|
||||
|
||||
if (params.has('term')) {
|
||||
this.$store.commit('Search/setTerm', params.get('term'))
|
||||
if (params.has('terms')) {
|
||||
console.log('Base created, has terms', params.get('terms'))
|
||||
// this.$store.commit('Search/setTerms', params.get('terms').split(','))
|
||||
this.$store.commit('Search/setTerms', JSON.parse(params.get('terms')))
|
||||
} else {
|
||||
this.$store.commit('Search/setTerm', '')
|
||||
this.$store.commit('Search/setTerms', [])
|
||||
}
|
||||
|
||||
if (params.has('filters')) {
|
||||
@ -91,7 +93,7 @@ export default {
|
||||
// when query change launch a new search
|
||||
console.log('Base beforeRouteUpdate', to, from, next)
|
||||
this.$store.commit('Search/setKeys', to.query.keys)
|
||||
this.$store.commit('Search/setTerm', to.query.term)
|
||||
this.$store.commit('Search/setTerms', to.query.terms)
|
||||
this.$store.commit('Search/setFilters', to.query.filters)
|
||||
this.pagetitle = to.query.keys
|
||||
this.newSearch()
|
||||
|
Reference in New Issue
Block a user