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

Fix validation issues #1245

Merged
merged 3 commits into from
Mar 1, 2024
Merged

Fix validation issues #1245

merged 3 commits into from
Mar 1, 2024

Conversation

steveyken
Copy link
Member

@steveyken steveyken commented Feb 28, 2024

The following features have been implemented:

  • all invalid core and custom fields should have red background highlighting
  • required custom fields are now indicated with '*'
  • field groups containing validation errors should always be expanded when returning the error messages (see screenshot)
  • FIX contact first_name showing '*' even when not required
  • added html5 'in browser' validation to core fields
  • upon form submit, reveal any hidden invalid fields in order to facilitate correction (otherwise, user has no idea why the form won't submit)
  • FIX remove '*' from several fields in task that looked required but have no validation

image

@steveyken steveyken requested a review from CloCkWeRX February 28, 2024 13:21
@steveyken steveyken marked this pull request as draft February 28, 2024 13:41
@steveyken
Copy link
Member Author

Hold for now. Just found a bug when creating a new Contact... the above works for 'edit' but not for 'new'

@steveyken steveyken marked this pull request as ready for review February 28, 2024 13:47
@steveyken
Copy link
Member Author

This is now ready for actual merge again. Assuming branch checks pass.

@CloCkWeRX
Copy link
Member

with ..

remove html5 'in browser' validation from custom fields to enable Rails validations to provide a better experience (form doesn't submit when section containing invalid custom field is collapsed and therefore not in view)

In general I really like to keep these behaviours. Better mobile UX, ability to use patterns, titles, etc.

The problem with collapsed/display none elements that are required is usually fixed by one of:

  • marking the elements disabled when they are hidden, so that the browser knows they aren't required. Use case is one form answer makes a subsequent area of the form mandatory
  • handling the before submit / validation event and when invalid, hidden elements are detected, marking the whole section visually invalid or expanding it

It's more work, but you get the best of both worlds then - instant UX feedback for the basics, and higher level domain errors from rails after submit.

Copy link
Member

@CloCkWeRX CloCkWeRX left a comment

Choose a reason for hiding this comment

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

Well, I wrote all that but don't actually see where you suppressed HTML5 behaviours, so lgtm

@steveyken
Copy link
Member Author

Yes, that all makes sense. My js isn't so strong but I'll give it a go. We'd need to expand sections that have invalid fields. I could potentially add html5 'required' attribute to the core fields that require validation too if you like e.g. account name, or contact first_name / last_name (dependent on settings).

Will update this PR in a bit.

p.s. the html5 validation was removed in app/models/fields/field.rb where 'required' was taken out of input_options which is fed to simple form in the view templates.

…submitting a form, show invalid fields that are in hidden sections in order to facilitate corrections.
@steveyken
Copy link
Member Author

I've updated the code now to re-enable html5 validations for custom fields and also to extend it to core fields also. If a custom field is hidden and invalid, some form submit JS will now open the section that contains the invalid field in order to display the validation message.

Bonus: removed '*' required asterisk from a few fields in task that had no underlying validation requirements.

I believe this is ready to merge now.

@steveyken
Copy link
Member Author

Ok for me to merge?

@CloCkWeRX
Copy link
Member

Sorry distracted by shiny things, let me look

@CloCkWeRX
Copy link
Member

That's really nice. Thank you for going the extra mile

@CloCkWeRX CloCkWeRX merged commit eb29df0 into master Mar 1, 2024
8 checks passed
@CloCkWeRX CloCkWeRX deleted the validation-improvements branch March 1, 2024 08:42
@steveyken
Copy link
Member Author

👍

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.

2 participants