SearchformVue e.selected bug fix (slim-select filters)

This commit is contained in:
Bachir Soussi Chiadmi 2025-04-28 17:38:15 +02:00
parent 7ec7d99554
commit 07ae40d703
7 changed files with 31 additions and 21 deletions

8
package-lock.json generated
View File

@ -62,7 +62,7 @@
"mini-css-extract-plugin": "^1.3.1", "mini-css-extract-plugin": "^1.3.1",
"querystring-es3": "^0.2.1", "querystring-es3": "^0.2.1",
"sass-loader": "^10.1.0", "sass-loader": "^10.1.0",
"slim-select": "^2.10.0", "slim-select": "^2.11.0",
"style-loader": "^2.0.0", "style-loader": "^2.0.0",
"uglify-es": "^3.3.9", "uglify-es": "^3.3.9",
"url-loader": "^4.1.1", "url-loader": "^4.1.1",
@ -11560,9 +11560,9 @@
} }
}, },
"node_modules/slim-select": { "node_modules/slim-select": {
"version": "2.10.0", "version": "2.11.0",
"resolved": "https://registry.npmjs.org/slim-select/-/slim-select-2.10.0.tgz", "resolved": "https://registry.npmjs.org/slim-select/-/slim-select-2.11.0.tgz",
"integrity": "sha512-sOKXH8YlgspTn+wy1jYbscVlFbBsAIOmtrmx1e16sV+NbYDTIyJCCdLH0EL9gDxDdHzBgE/s5XZ+VChaxz0JGg==", "integrity": "sha512-Y0FEJKIPBy8ax7jArUxICxtKAnhX8GH7ydaFhcrYH7OznfpvxCe8uU2etyuRPKhE23c2LhT2GROFvZzGVplA0g==",
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },

View File

@ -71,7 +71,7 @@
"mini-css-extract-plugin": "^1.3.1", "mini-css-extract-plugin": "^1.3.1",
"querystring-es3": "^0.2.1", "querystring-es3": "^0.2.1",
"sass-loader": "^10.1.0", "sass-loader": "^10.1.0",
"slim-select": "^2.10.0", "slim-select": "^2.11.0",
"style-loader": "^2.0.0", "style-loader": "^2.0.0",
"uglify-es": "^3.3.9", "uglify-es": "^3.3.9",
"url-loader": "^4.1.1", "url-loader": "^4.1.1",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -31,14 +31,14 @@ export default {
}, },
methods: { methods: {
submit() { submit() {
console.log("search submited", this.typed, this.autocomplete, this.filters, this.slimFilters) console.log("slim search submited", this.typed, this.autocomplete, this.filters, this.slimFilters)
// unfocus the text input to hide the keyboard on mobile device // unfocus the text input to hide the keyboard on mobile device
this.$input.blur() this.$input.blur()
// New search is triggered by Base.vue with router (which will also fill the store) // New search is triggered by Base.vue with router (which will also fill the store)
// cleaning slimfilters // cleaning slimfilters
let filters = [] let filters = []
this.slimFilters.forEach((filter, index) => { this.slimFilters.forEach((filter, index) => {
console.log('onsubmit foreach filters', filter) console.log('onsubmit foreach slimFilters', filter)
if(filter){ if(filter){
filters.push(filter) filters.push(filter)
} }
@ -93,8 +93,10 @@ export default {
}, },
onSelectFiltersChange(index, info){ onSelectFiltersChange(index, info){
console.log('onSelectFiltersChange', index, info, this.slimFilters, this.filters) console.log('slim onSelectFiltersChange', index, info, this.slimFilters, this.filters)
this.slimFilters[index] = info.value this.slimFilters[index] = info.value
console.log(this.slimFilters);
}, },
onClickFilters(e){ onClickFilters(e){
console.log('onClickFilters legend', e) console.log('onClickFilters legend', e)
@ -175,8 +177,12 @@ export default {
// customize the select filters // customize the select filters
// http://slimselectjs.com/options // http://slimselectjs.com/options
const selects = this.$el.querySelectorAll('select') const selects = this.$el.querySelectorAll('select')
console.log('slim selects', selects);
let slim; let slim;
selects.forEach((selectElement, index) => { selects.forEach((selectElement, index) => {
console.log('slim selects forEach', selectElement, index);
// get the first option to make the placeholder then empty it // get the first option to make the placeholder then empty it
const placeholder_option = selectElement.querySelector('option:first-child') const placeholder_option = selectElement.querySelector('option:first-child')
// console.log('placeholder_option', placeholder_option); // console.log('placeholder_option', placeholder_option);
@ -185,20 +191,24 @@ export default {
placeholder_option.setAttribute("data-placeholder", true) placeholder_option.setAttribute("data-placeholder", true)
placeholder_option.innerHTML = '' placeholder_option.innerHTML = ''
slim = new SlimSelect({ slim = new SlimSelect({
events:{
afterChange: (newval) => {
console.log('slim slimselect onchange', index, newval, this)
this.onSelectFiltersChange(index, newval[0])
}
},
select: selectElement, select: selectElement,
placeholder: placeholder, placeholder: placeholder,
// allowDeselect: true allowDeselect: true,
allowDeselectOption: true,
showSearch: false, showSearch: false,
closeOnSelect: true, closeOnSelect: true
onChange: (info) => {
this.onSelectFiltersChange(index, info)
}
}) })
console.log('slimselect selected', slim.selected(), index) console.log('slim', slim);
this.slimFilters[index] = slim.selected() // console.log('slimselect selected', slim, slim.selected(), index)
this.slimFilters[index] = slim.getSelected()[0];
}) })
console.log('slimSelect after init', this.slimFilters) console.log('slimSelect slimFilters after init', this.slimFilters)
}, },
render(h) { render(h) {
// console.log('searchForm render') // console.log('searchForm render')