question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service Validations should format error messages for form helpers

See original GitHub issue

Not sure how I missed this, but I realized as I’m going back through the tutorial for 1.0 that the error messages raised by Service Validations aren’t quite the right format for Form Helpers to parse them apart and highlight the fields that are invalid.

When we setup validation from scratch in the tutorial we raise this error:

throw new UserInputError("Can't create new contact", {
  messages: {
    email: ['is not formatted like an email address'],
  },
})

Which, when using form helpers <FormError> and <FieldError> results in:

image

But replacing the custom validation with Service Validations like:

validate(input.email, 'Email', {
  email: true,
})

results in this:

image

Ideally it would highlight the errored field, in addition to providing the blanket message the top.

I should be able to add this without too much fuss, but may be a breaking change for error handling in user apps if they are doing something custom with errors outside of the form helpers.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
dthyressoncommented, Feb 18, 2022

Hmmm … but then the service is more tied to the form element:


export const createContact = ({ input }) => {
  validate(input.email, 'Email', {
    email: true,
    fieldName: 'email_4',
  })
  return db.contact.create({ data: input })
}

And that’s not great. And the key cannot be derived from the label to show because the human text may not be the input name.

Yeah, gotta think on this more.

0reactions
Tobbecommented, Mar 1, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Report Errors in Forms: 10 Design Guidelines
How to Report Errors in Forms: 10 Design Guidelines · 1. Aim for Inline Validation Whenever Possible · 2. Indicate Successful Entry for...
Read more >
Active Record Validations - Ruby on Rails Guides
Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers provide common validation rules.
Read more >
Improve Validation Errors with Adaptive Messages
Validation errors won't ever be eliminated – they are a natural part of complex forms and user inputs. In this article we share...
Read more >
Usable and Accessible Form Validation and Error Recovery
Form validation ensures that web forms are filled out with all necessary information in the correct format. Error recovery guides a user to...
Read more >
Form validation and error handling - IU KB - Indiana University
Client-side validation can help identify errors before the form is submitted, but the interruptions from error messages can also be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found