rubyforgood / casa

Volunteer management system for nonprofit CASA, which serves foster youth in counties across America.
https://casavolunteertracking.org/
MIT License
305 stars 472 forks source link

[5921] Show the first error messages of each attribute in forms #5976

Closed ElisaRmz closed 4 weeks ago

ElisaRmz commented 1 month ago

What github issue is this PR for, if any?

Resolves #5921

What changed, and why?

The issue involved multiple error messages when creating a Casa case with a blank court date and/or a blank birth month year youth.

I have modified the validations in casa_case model. With this partial only one error message is shown per field in the form.

How is this tested? (please write tests!) 💖💪

Note: if you see a flake in your test build in github actions, please post in slack #casa "Flaky test: " :) 💪 Note: We love capybara tests! If you are writing both haml/js and ruby, please try to test your work with tests at every level including system tests like https://github.com/rubyforgood/casa/tree/main/spec/system

Screenshots please :)

Replicating the previous steps in the issue:

Captura de pantalla 2024-08-22 a las 15 47 02

Feelings gif (optional)

What gif best describes your feeling working on this issue? https://giphy.com/ How to embed: ![alt text](https://media.giphy.com/media/1nP7ThJFes5pgXKUNf/giphy.gif)

thejonroberts commented 1 month ago

@ElisaRmz I saw something like the requested changes recently in the CaseContact model:

  validates :occurred_at, presence: true
  validates :occurred_at, comparison: {
    greater_than_or_equal_to: MINIMUM_DATE,
    message: "can't be prior to #{I18n.l(MINIMUM_DATE)}.",
    allow_nil: true
  }
  validates :occurred_at, comparison: {
    less_than: Date.tomorrow,
    message: :cant_be_future,
    allow_nil: true
  }

The allow_nil is the key part! Hope that helps!

ElisaRmz commented 1 month ago

I applied the changes suggested in the review.

Let me know if it's what you expected :)

@elasticspoon @thejonroberts