H
H
hadaev_ivan2015-05-27 19:40:29
JavaScript
hadaev_ivan, 2015-05-27 19:40:29

How do you organize validations in flux/react.js?

In my project I am using react.js and something similar to flux. There is one huge object that is responsible for the state of almost everything, the dispatcher listens to events in the components and updates this object, as a result, the react renders the changes to the page. All clear. But when it came to complex dynamically generated forms and complex validations, the question arose how to organize it all? It's clear that the validation itself should be somewhere near the dispatcher, but how to correctly convey these errors to the components?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
1
123 123, 2015-05-27
@hadaev_ivan

Ideally, you should have a type component <InputValidator />that wraps the input field and has validation logic in it. You can pass validation rules (pattern, length, etc.) to this component, and onChangedispatch and update the global state on it.
The validity status can be passed directly to onChange, as the second parameter, after the event, or added to the event object.
A component with field validation shouldn't be bound internally to your code, it should be a black box.

C
ctpayc, 2015-07-09
@ctpayc

and I liked this library https://github.com/christianalfoni/formsy-react

I
IvanKalinin, 2017-08-10
@IvanKalinin

For my projects I use my web-form-validator library

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question