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

Modify validations behaviour #3108

Merged
merged 2 commits into from
Oct 17, 2024
Merged

Conversation

sammo1235
Copy link
Contributor

@sammo1235 sammo1235 commented Oct 17, 2024

See ticket for changes need, they do a good job of explaining the issues this PR attempts to solve. There is also a list of form questions this is relevant to (basically they are date, financial info, personal details and previous award wins).

📝 A short description of the changes

  • If form starts off empty, then we don't add validation errors for all the inputs the user has not yet touched.
  • however, if we go back and delete an input, then it should show the validation error for that input.
  • If the user navigates between different steps of the form (using save or the navigation menu on the left) then all validation errors should show, as before. However, now the behaviour has changed to only remove validation errors for the inputs that the user has touched, not clearing them wholesale like before.

There are two main modes to understand when reviewing the code - @validate_only_touched_inputs will be false when navigating around the different form steps (because we want to validate everything) and will be true once they start to interact with the inputs on a form (since we only care about validating what they touch).

🔗 Link to the relevant story (or stories)

:shipit: Deployment implications

  • Very little, this is just JS changes

✅ Checklist

  • Features that cannot go live are behind a feature flag/env var or specify deploy date and open PR as draft
  • I have checked that commit messages make sense and explain the reasoning for each change
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have squashed any unnecessary or part-finished commits

🖼️ Screenshots (if appropriate - no PII/Prod data):

@matthewford
Copy link
Contributor

I like the fact that this is a JS change only, which means there should be little knock-on effects on updating the form in later workflow steps.

Comment on lines 296 to 299
questionYearTouched = !!question.find('.js-date-input-year.dirty').length
questionMonthTouched = !!question.find(".js-date-input-month.dirty").length
questionDayTouched = !!question.find(".js-date-input-day.dirty").length
allTouched = questionYearTouched && questionMonthTouched && questionDayTouched
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are probably cleaner ways of doing this in coffee

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
questionYearTouched = !!question.find('.js-date-input-year.dirty').length
questionMonthTouched = !!question.find(".js-date-input-month.dirty").length
questionDayTouched = !!question.find(".js-date-input-day.dirty").length
allTouched = questionYearTouched && questionMonthTouched && questionDayTouched
[yearTouched, monthTouched, dayTouched] = ['.js-date-input-year', '.js-date-input-month', '.js-date-input-day'].map (cls) ->
!!question.find("#{cls}.dirty").length
allTouched = yearTouched and monthTouched and dayTouched

It's not really much cleaner, though; I prefer the simplicity.

el.append(message)
else
el.append(" #{message}")
if not el.text().includes(message)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we now don't clear the entire question block for validation error before revalidating, we have to be careful not to add duplicate errors to the same elements

Do not show vaildations prematurely in multipart questions
Do not clear all validation errors after one edit in multipart questions
Only validate inputs that have been touched when editing a form
@sammo1235 sammo1235 force-pushed the sam/KAEIMP23/stop-premature-validations branch from f89e767 to df1bdc3 Compare October 17, 2024 14:52
@sammo1235 sammo1235 merged commit 24a5609 into main Oct 17, 2024
10 of 11 checks passed
@sammo1235 sammo1235 deleted the sam/KAEIMP23/stop-premature-validations branch October 17, 2024 15:12
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.

3 participants