This package subscribes to @simplr/react-forms
store and it will validate on emitted actions.
- Validates fields on form store actions (
FieldRegistered
,ValueChanged
,PropsChanged
) - Subscribes to form store handler and form stores to listen actions
- Premade validators like: Email, Required, Contains etc.
To initialise module you need to import subscriber once in your app.
import { InitializeValidation } from "@simplr/react-forms-validation";
InitializeValidation();
import { Form, Text, Password } from "@simplr/react-forms-dom";
import { RequiredValidator, EmailValidator } from "@simplr/react-forms-validation";
export function LoginForm(props: {}) {
return <Form>
<Text name="username">
<RequiredValidator error="Username field is required" />
<EmailValidator error="Username is not valid" />
</Text>
<Password name="password">
<RequiredValidator error="Password field is required" />
</Password>
<button>Submit</button>
</Form>;
}
}