psaia / react-serial-forms

A lightweight and extendable SSR-friendly form library (for React).
167 stars 18 forks source link

Where should I declare the custom validators ? #5

Closed carlosrberto closed 9 years ago

carlosrberto commented 9 years ago

I'm using modules, where should I declare the custom validators ?

psaia commented 9 years ago

Define validators before you use them. Exporting objects in modules is an anti-pattern - the modules simply export the reference to that object. The updated object will persist.

shawnbissell commented 9 years ago

@petesaia I'm also using modules with browserify/reactify. I have no idea how to where to declare the custom validators to have the "stick" to the exported validators object. It always seems to be redefined right before my form is rendered. I tried in to define a validator at the top of my module and also right inside the render method. Can you give an example define what you mean by "before you use them"?

psaia commented 9 years ago

Reopening. I will provide examples and perhaps a betters API to do this.

psaia commented 9 years ago

This has been greatly approved. Please see here: https://github.com/LevInteractive/react-serial-forms#custom-validators