materiotheme: search field as a Vue form, one phrase (F1)
- SearchForm.vue: one search field (150 characters, like the backend) and a button; Enter and button submit the same way; route base with keys only (no more terms nor filters). Same ids and classes as the former Drupal form, so main.scss applies. - SearchBlock.vue: no more fetching nor Vue.compile of the Drupal form. - Base.vue: aria-live on the result message, announced by screen readers. - Production build (npm run prod). Suggestions in the field come back in F7 (they came from the jQuery UI autocomplete of the Drupal form). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM
This commit is contained in:
@@ -1,79 +1,21 @@
|
||||
<template v-slot="default">
|
||||
<div v-bind:id="blockid">
|
||||
<SearchForm
|
||||
v-if="displayform"
|
||||
v-bind:form="form"></SearchForm>
|
||||
<SearchForm v-if="canSearch"></SearchForm>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import qs from 'querystring-es3'
|
||||
|
||||
import SearchForm from 'vuejs/components/Form/SearchForm'
|
||||
import { mapState, mapActions } from 'vuex'
|
||||
import MA from 'vuejs/api/ma-axios'
|
||||
import { mapState } from 'vuex'
|
||||
|
||||
export default {
|
||||
// formhtml: HTML of the former Drupal form, still passed by main.js, no
|
||||
// longer used: the form is a Vue component (F1).
|
||||
props: ['blockid', 'formhtml'],
|
||||
data(){
|
||||
return {
|
||||
form: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
canSearch: state => state.User.canSearch,
|
||||
keys: state => state.Search.keys,
|
||||
terms: state => state.Search.terms,
|
||||
filters: state => state.Search.filters
|
||||
}),
|
||||
displayform(){
|
||||
// console.log('computed displayform')
|
||||
return this.canSearch && this.form
|
||||
}
|
||||
},
|
||||
beforeMount() {
|
||||
// console.log('SearchBlock beforeMount')
|
||||
this.form = this.formhtml
|
||||
},
|
||||
watch: {
|
||||
canSearch(new_value, old_value) {
|
||||
// console.log('canSearch changed, old: '+old_value+", new: "+new_value)
|
||||
if (new_value && !this.form) {
|
||||
this.getSearchForm()
|
||||
}
|
||||
if (!new_value && this.form) {
|
||||
this.form = null
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getSearchForm(){
|
||||
console.log('getSearchForm')
|
||||
// var urlParams = new URLSearchParams(window.location.search);
|
||||
// var urlParamsKeys = urlParams.keys()
|
||||
const params = {
|
||||
keys: this.keys,
|
||||
terms: this.terms, //JSON.stringify(this.terms),
|
||||
filters: this.filters
|
||||
}
|
||||
console.log('Search getSearchForm params', params)
|
||||
const q = qs.stringify(params)
|
||||
MA.get(`/materio_sapi/search_form?`+q)
|
||||
.then(({data}) => {
|
||||
// console.log('getSearchForm')
|
||||
// guard against unexpected response body (truncated / non json)
|
||||
// which would crash Vue.compile(undefined) in SearchForm
|
||||
if (typeof data.rendered !== 'string') {
|
||||
console.warn('SearchBlock getSearchForm unexpected data', data)
|
||||
return
|
||||
}
|
||||
this.form = data.rendered
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn('Issue with get searchform', error)
|
||||
})
|
||||
}
|
||||
canSearch: state => state.User.canSearch
|
||||
})
|
||||
},
|
||||
components: {
|
||||
SearchForm
|
||||
|
||||
Reference in New Issue
Block a user