www.fgks.org   »   [go: up one dir, main page]

Skip to content
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

Show error messages without clearing inputs in edition edit page #8777

Conversation

rebecca-shoptaw
Copy link
Collaborator
@rebecca-shoptaw rebecca-shoptaw commented Jan 30, 2024

Closes #8423

Fix. Makes the inputs for adding contributors, classifications, identifiers, excerpts and links (on the Edit page and the Work Details page) only clear once the input is accepted -- to make it easier for users to fix typos/etc. if rejected instead of having to re-type their entry.

Technical

This ended up being a little more involved than expected. Since the values were automatically clearing (to be saved separately in a data variable) before the error checks ran, I initially implemented a workaround solution that used the data values to manually re-set the input fields to their lost values after the error checks.

After this, I discovered that the root of the problem was actually in the jquery.repeat.js file, where all text inputs were being cleared as a side effect of storing the values in data.

So I removed that line from the function, and added value clearing to each relevant function to run only after the error checks pass. I.e. $('#select-role, #role-name').val('');

This all worked great, and made the UI behave as desired -- and had the added benefit of clearing the role/identifier type as well when the entry is accepted.

Edit: Got the tests passing by adjusting the process for identifier validation specifically -- formdata now does clear the inputs, but just for identifier entries. The inputs are re-entered via $('#id-value).val(data.value) in a couple places so that the input remains in the case of errors like no identifier type selected.

Other Technical Notes

This also involved some cleanup along the way, specifically fixing some typos in the calls to the error() function to make sure the error message displayed and the correct input was focused on, and two quick HTML rewrites to improve the URL validation in web.html and make the excerpt error show/hide properly in excerpts.html.

Testing

  1. While logged in, go to an edition edit page.
  2. Enter a contributor without selecting a role (or vice versa) -- error message should appear without input fields clearing
  3. Fix the problem and submit -- error message should disappear and input fields should clear.
  4. Can follow the same process for classification/identifier/link/excerpt errors

Screenshot

Contributor Validation

Stakeholders

@jimchamp

@rebecca-shoptaw rebecca-shoptaw changed the title 8423/show error msg without clearing input Show error messages without clearing inputs in edition edit page Jan 30, 2024
@rebecca-shoptaw rebecca-shoptaw force-pushed the 8423/show-error-msg-without-clearing-input branch from 8802d00 to 924fa07 Compare January 30, 2024 19:12
@rebecca-shoptaw rebecca-shoptaw marked this pull request as ready for review January 30, 2024 19:14
@codecov-commenter
Copy link

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (7927be4) 16.62% compared to head (924fa07) 16.65%.

Files Patch % Lines
openlibrary/plugins/openlibrary/js/edit.js 56.25% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8777      +/-   ##
==========================================
+ Coverage   16.62%   16.65%   +0.03%     
==========================================
  Files          88       88              
  Lines        4698     4706       +8     
  Branches      838      838              
==========================================
+ Hits          781      784       +3     
- Misses       3399     3404       +5     
  Partials      518      518              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jimchamp jimchamp self-assigned this Feb 1, 2024
Copy link
Collaborator
@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rebecca-shoptaw, and sorry for the delay! Great job on this. I think that we mislabeled the corresponding issue as a Good first issue, as the validation code isn't the easiest to work with...

Because this hasn't been reviewed in a timely manner, I'm going to commit my suggested changes and merge this. If any of my changes seem wrong to you, let me know and we can fix it.

openlibrary/plugins/openlibrary/js/jquery.repeat.js Outdated Show resolved Hide resolved
openlibrary/plugins/openlibrary/js/jquery.repeat.js Outdated Show resolved Hide resolved
openlibrary/templates/books/edit/web.html Outdated Show resolved Hide resolved
@jimchamp jimchamp merged commit 526765c into internetarchive:master Feb 22, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add front-end validation to Contributor for role (so name is not cleared on submit)
3 participants