Add single-character author search frontend validation#11854
Open
agabedc wants to merge 6 commits intointernetarchive:masterfrom
Open
Add single-character author search frontend validation#11854agabedc wants to merge 6 commits intointernetarchive:masterfrom
agabedc wants to merge 6 commits intointernetarchive:masterfrom
Conversation
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds frontend validation to prevent single-character author searches, addressing part of issue #9290. The implementation uses vanilla JavaScript to dynamically set HTML5 validation attributes (minlength, pattern) on search inputs when the "Author" search category is selected. The validation is applied in two key locations: the dedicated author search page and the navbar search bar.
Changes:
- Added client-side validation requiring at least 2 characters for author searches
- Modified searchbox template to accept an optional category parameter
- Implemented inline JavaScript validation scripts in both navbar and author search page
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| openlibrary/templates/search/searchbox.html | Added category parameter to template definition and inline script that applies validation attributes when category is 'authors' |
| openlibrary/templates/search/authors.html | Updated to pass category='authors' when rendering searchbox template |
| openlibrary/templates/lib/nav_head.html | Added inline script to dynamically apply/remove validation based on selected search facet (author vs. other types) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
for more information, see https://pre-commit.ci
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses some of the acceptance criteria for ticket #9290
Handles frontend validation for searching authors from both the https://openlibrary.org/search/authors search page and navbar search, restricting searches of only 1 character when "Author" is selected.
Technical
It should be noted that this only addresses some of the acceptance criteria for ticket #9290 -- not all of it. Also, our solution uses vanilla JavaScript to modify HTML attributes on the client side as opposed to if-statements in the Web.py templating.
We are submitting what we have so far so that a stakeholder can review our code before moving ahead with backend validation and author additions.
Testing
Screenshot
Stakeholders
@cdrini, @mekarpeles