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.

Field has error but is still valid

See original GitHub issue

Hey there, thanks for this great library! Everything worked perfectly so far, except now I have a very strange behavior for a text field that has errors (they are even shown in the form correctly) but still validates to true and the onSuccess handler is called on the form.

Here is a screenshot of the console.log output of the form.get call for this field: screenshot 2016-10-28 um 13 56 33

I guess this state (errors are set & displayed but field hasError is false) should not be possible?

It worked fine on a form where we used material-ui and now im trying it with react-toolbox although i don’t think that is the problem?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
darko-mijiccommented, Oct 31, 2016

Thanks @foxhound87. We where using react-intl and our validators where returning an object instead of a string for validation errors. This was causing the issue.

From @DominikGuzei’s example:

const isValidWalletName = ({ field }) => {
  const isValid = field.value.length >= 3;
  return [isValid, messages.invalidWalletName]; // this is defined elsewhere (not important)
};

messages.invalidWalletName was an object:

invalidWalletName: {
    id: 'wallet.create.form.errors.invalidWalletName',
    defaultMessage: '!!!The wallet name must have at least 3 letters.',
    description: 'Error message shown when invalid wallet name was entered in create wallet dialog.'
  }

And it needed to be a string so the fix was to provide a validator with i18n features of react-intl to return a string for validation error instead of passing an object.

0reactions
foxhound87commented, Oct 31, 2016

I don’t know how react-intl work, I never used it. You can try to use stateless components if you are using classes with local state. If you can setup a small test project I will take a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is an Angular form VALID with no mat-error when it has ...
1. When I set an error via the customValidator on the form, the form.status remains VALID even when there are form.errors ...
Read more >
How to Troubleshoot and Fix Excel Pivot Table Errors
The pivot table error, "field name is not valid", usually appears because one or more of the heading cells in the source data...
Read more >
Form-Field Validation: The Errors-Only Approach
With all form fields still displayed (valid or not), the user might have difficulty identifying the few erroneous fields among the many valid...
Read more >
Solved: If Validation and Error Message Issue
Solved: Hi, I am trying to validate the below code, not getting required output. Here I am validating either the user has uploaded...
Read more >
forms: validation. don't show errors until the user has had a ...
When a user opens a page that has a bunch of required fields, all they see is a bunch of red. Not very...
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