-
Notifications
You must be signed in to change notification settings - Fork 3
Limit autocomplete to keyword searches #925
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
Draft
marlo-longley
wants to merge
1
commit into
main
Choose a base branch
from
hide-autocomplete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| export default function initializeAutocompleteToggle() { | ||
| const searchField = document.querySelector('#search_field'); | ||
| const autocomplete = document.querySelector('.search-autocomplete-wrapper'); | ||
| const autocompleteSrc = autocomplete?.src; | ||
|
|
||
| // Update the autocomplete display based on the selected search field value | ||
| function updateAutocompleteDisplay() { | ||
| const selectedSearchField = searchField.value; | ||
|
|
||
| if (selectedSearchField === "keyword") { | ||
| autocomplete.setAttribute("src", autocompleteSrc) | ||
| } else { | ||
| // Remove the src attribute to hide the autocomplete | ||
| autocomplete.removeAttribute("src"); | ||
| } | ||
| } | ||
|
|
||
| if (searchField && autocomplete) { | ||
| searchField.addEventListener('change', updateAutocompleteDisplay); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Is there a reason you aren't using Stimulus for this? All of the other JS for this app uses Stimulus.
Uh oh!
There was an error while loading. Please reload this page.
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.
I wrote this in Stimulus first. I needed to copy down the Blacklight template for the search bar in order to insert the Stimulus targets, controller, etc. into the markup. I got the feedback that this seemed messier than writing vanilla JS. With vanilla JS, there was no need to copy down the Blacklight component. So I rewrote it this way.
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.
By making that choice, you are binding to selectors that are not guaranteed to be stable between versions of blacklight/arclight. This seems more dangerous to me, even though it might be less code.
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 makes sense, thanks for the feedback. The team decided put this to draft for now as we learn more about what the stakeholders actually want from this feature.