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

Invalid state for the new form #5

Closed
kmmbvnr opened this issue May 11, 2016 · 4 comments
Closed

Invalid state for the new form #5

kmmbvnr opened this issue May 11, 2016 · 4 comments

Comments

@kmmbvnr
Copy link

kmmbvnr commented May 11, 2016

It's pretty uncommon to see error messages on empty new form.

Ex in user list example, as soon as Add user button clicked.

nestedreact todomvc

Is there any way in valuelink library to postpone the validation till user navigates out of the field, or press submit button?

@gaperton
Copy link

Sure you can. Like this:

  1. Add 'ingnoreIsRequired' attribute to the state, and set it to true in onSubmit handler.
  2. In "is required" validation checks, instead of x => x it should be x => ignoreIsRequired || x
  3. In the next checks emptiness guards are needed.
  4. In submit button, you have to manually detect whenever required state members are empty.

@gaperton
Copy link

gaperton commented May 11, 2016

But I don't see any advantage in not telling the user from the beginning which fields are required.

What I would probably done if our QA would be bothered, is introducing different styles for error messages. error object can have any shape.

.check( x => x, { type : 'required', name : 'Name' })

Then, I would modify Input controls so they will style different error types differently. And this 'field required' message wouldn't look that scary.

@gaperton
Copy link

gaperton commented May 11, 2016

To do it in better way you need something more advanced than plain React state. Problem here is that checks are not attached to the state, they are inlined in render(). Which is okay for many cases, but you cannot run checks outside of render. This is rather serious restriction.

If you use models instead of the React state, you can. Cause checks will be attached to the model attributes, and your can validate model as a whole or by parts at any time you want. Which allows for variety of different validation strategies.

That's what we're doing. We are not using React state in production at all. And these links are attached to the models, so you can be quite flexible in approach to validation.

https://github.com/Volicon/NestedReact#link-validation

@gaperton
Copy link

gaperton commented May 27, 2016

Whenever input value is an empty string, and validation fails, it will add 'required' class to the input control. Thus, you will have an opportunity to mark it differently. With yellow, for example. Changes are now in 'develop' branch, will be released soon.

Thanks for the bug, it's was really the good point.

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

No branches or pull requests

2 participants