Replace all jQuery validate
instances with built-in HTML or JS validation
#9605
Labels
Lead: @cdrini
Issues overseen by Drini (Staff: Team Lead & Solr, Library Explorer, i18n) [managed]
Priority: 3
Issues that we can consider at our leisure. [managed]
Type: Epic
A feature or refactor that is big enough to require subissues. [managed]
Type: Feature Request
Issue describes a feature or enhancement we'd like to implement. [managed]
Type: Refactor/Clean-up
Issues related to reorganization/clean-up of data or code (e.g. for maintainability). [managed]
Problem
As part of an overall reduction of the OL code size to improve site performance, one of the most obvious and easiest targets is jQuery validate, a form validation plugin that can be almost completely duplicated with simpler, faster built-in HTML checks.
Current behavior:
Currently, the plugin is used like so to ensure required inputs are filled, emails are correctly formatted, and the publish date is not more than a year in the future:
openlibrary/openlibrary/plugins/openlibrary/js/validate.js
Lines 7 to 16 in b010f39
Not only is the current implementation inefficient, but it has bizarre, non-user-friendly side-effects. For instance:
/contact
page, therequired
attribute on the "Your Question" field, instead of displaying the desired error message if the form is submitted with an empty question, actually hides the whole question field, making the form impossible to submit:type="email"
is added to an email input in a form using jQueryvalidate
, the plugin adds non-user-friendly and visually awkward on-key-up validation as the user types/add
, are located only in the JavaScript, and cannot be translated - which you can verify by searchingmessages.pot
for "Are you sure that"Proposal & Constraints
Since in practice jQuery validate is only used for 3 different checks, removing it should be very simple, and involve just:
class="required"
in a jQuery validate form with the HTMLrequired
attributeclass="email"
in a jQuery validate form with the HTMLtype="email"
attributepublish-date
custom validation, which is only used inadd.html
:a. Move the existing publish date validation function into the
add-book.js
file which handles other JS validation for the formb. Add the error message to the HTML so it can be correctly internationalized
c. Ensure the function fires on the correct input on blur
validate
class from each relevant form, remove the invocation fromindex.js
, deletevalidate.js
, and uninstall the pluginSubtasks
validate
in admin and support forms #9607validate
in book/author/tag edit forms #9608validate
in book add form #9610validate
from codebase #9816Related files
validate.js
support.html
/admin/people/index.html
/admin/people/view.html
/books/add.html
/books/edit.html
/tag/add.html
/tag/edit.html
/author/edit.html
Stakeholders
@cdrini
Instructions for Contributors
The text was updated successfully, but these errors were encountered: