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

4157 donation site visible after error #4263

Merged

Conversation

luca652
Copy link
Contributor

@luca652 luca652 commented Apr 10, 2024

Resolves #4157

  • The issue affected the creation of a new donation. If a user selected Donation Site in Source, but didn't select a value for Donation Site and saved, the page re-rendered with an error but the Donation Site field was not be visible.
  • I modified app/javascript/utils/donations.js
  • The issue originated with the hide_fields_with_no_value function. The function checked if certain fields (among which Donation Site) had a value selected, and hid them if they did not. This worked on page load, but created the issue when re-rendering the form.
  • I deleted hide_fields_with_no_value.
  • I noticed that the function on line 73, which ran on a 'change' event, checked the value of the Donation Source field and toggled the relevant fields, so I decided to use it on page load as well.
  • I named it 'handleSourceSelection' and made it run both on page load and on a 'change' event. Now if there is no value selected in the source field, the optional fields are hidden. If a value is selected, the relevant fields appear.
  • The issue is solved. If a user selects Donation Site in Source, does not select a value for Donation Site and saves, the page re-renders with an error and the Donation Site field is visible.
  • I added a test in donation_system_spec.rb (line 415), which selects Donation Site from Source, selects a Storage Location (but does not select a Donation Site) and attempts to save. The test checks the page for a visible div with class "donation_donation_site" and for the error message "Where was this donation dropped off?"

being shown on form submission

- The issue occurred when creating a donation and selecting 'Donation Site'
as the 'Source' without choosing a value for the 'Donation Site' field.
After submitting the form, the error message was displayed correctly,
but the 'Donation Site' field remained hidden.
- Removed the `hide_fields_with_no_value(fields_to_hide)` and renamed function
on line 64 `handleSourceSelection`. This function is called on page load and
on the 'change' event, and checks if a value is selected in the Source field and
toggles the display of connected fields.
field on page re-render

This commit adds a new test to ensure that when the user selects 'Donation Site'
as Source for a new donation, doesn't select a Donation Site, and then attempts
to save the donation, the page is re-rendered with the donation site field visible
and an error message displayed.

Additionally, refactor handler function to improve efficiency
The commit also includes changes to the handler function responsible for managing
the visibility of form fields based on user input. Specifically, the handler code
is now executed only when the control_id element is present on the page.
@dorner
Copy link
Collaborator

dorner commented Apr 11, 2024

This looks good to me! Definitely a simpler approach. 😄

@dorner dorner merged commit 134f99d into rubyforgood:main Apr 11, 2024
19 checks passed
@luca652
Copy link
Contributor Author

luca652 commented Apr 11, 2024

Great! Thanks Daniel.

Copy link
Contributor

@luca652: Your PR 4157 donation site visible after error is part of today's Human Essentials production release: 2024.04.14.
Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants