New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(search): populate Search field with user provided value #1019
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to try something more "official" like you say before merging, I'll have a look at it tomorrow!
@oncletom do you have a reliable way of testing this? Because I'm having trouble :-/ You may try the code below. I'm hoping the created() {
if (this.$location.query.q) {
this.query = decodeURIComponent(this.$location.query.q.replace('+', ' '));
}
},
data() {
// const query = this.$location.query.q || '';
return {
current: -1,
query: null,
show: false,
cache: new Cache('site-search', sessionStorage),
groups: [
group('datasets', this._('Datasets')),
group('reuses', this._('Reuses')),
group('organizations', this._('Organizations'), 'organization'),
group('territory', this._('Territories'), 'territory'),
],
minLength: 2,
placeholders: placeholders,
}
}, |
@abulte I will give a go at it tomorrow (will be in the office) 👋 if you are around — I agree it would be nicer to compute the field value only once ( |
const originalField = this.$options.el.querySelector('#search'); | ||
const queryStringValue = decodeURIComponent(query.q.replace('+', ' ')); | ||
|
||
this.query = originalField.value || queryStringValue || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does the trick. We either pick:
- the value at runtime of the search field (altered by user or provided by a
input[value]
attribute; - otherwise we pick it up from the query string;
- otherwise field value has not been setup
@abulte I have made the change 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing CHANGELOG but OK.
Changelog updated 👍 |
This pull request populates the query field when the Vue component is initialised.
The Good
It works.
The Bad
I have not found any particular documentation for
$options.el
so it might break when upgrading Vue.js.There are probably better ways to do:
value="..."
property to the search field as a prop (could not figure out how to pass the paramter to the search macro)The Ugly
The Vue component relies on the DOM of the original so it can break just by changing the HTML template.
What's next?
Once this issue is fixed, I would like to remove the code duplication between the HTML view and the Vue component. Either by extending the form and providing only the autocomplete feature.
fix #1016