Git Product home page Git Product logo

Comments (4)

gaperton avatar gaperton commented on July 29, 2024

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.

from nestedlink.

gaperton avatar gaperton commented on July 29, 2024

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.

from nestedlink.

gaperton avatar gaperton commented on July 29, 2024

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

from nestedlink.

gaperton avatar gaperton commented on July 29, 2024

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.

from nestedlink.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.