ValidatorForm
Extends:
Component → ValidatorForm
Form with integrated validation support
- use with Prg Validator utility
PropTypes
property | type | type signature | description |
---|---|---|---|
t |
function |
word => 'string' |
translator provided to validator |
className |
string |
form class name | |
validator |
string |
required | validator |
values |
object |
values to fill the form | |
onChange |
function |
(inputName, input) => {} ) |
form change handler |
onBeforeValidate |
function |
(values) => {} |
fired after submit, before validation |
onSubmit |
function |
(values) => {} |
fired after sucessfully validated submit |
onValidationFailed |
function |
(errors) => {} |
fired after unsucessfull validation |
validatorContext |
string |
is provided as parameter to validator |
Validator interface
- validateProp(
inputName: string, value: any, ctx: string, data: object
) : Promise- fired after
onChange
event inputName
- name of the inputvalue
- current input valuectx
- passedvalidatorContext
data
- values of other inputs in form
- fired after
- validate(
data: object, ctx: string
) : Promise- fired after
onSubmit
event data
- whole form datactx
- passedvalidatorContext
- fired after
Example:
import { ValidatorForm, Input } from 'prg-form';
import Validator from 'prg-validator';
function MyForm ({ values }) {
const validator = new Validator();
validator.add('email')
.isEmail('Email should be valid');
return (
<ValidatorForm
className="special-class"
onSubmit={(values, form) => console.log(values)}
onChange={(input) => console.log(input.name, input.getValue())}
validator={validator}
values={values}
>
<Input type="email" name="inputName" label="Input Label" />
</Form>
);
}
Method Summary
Public Methods | ||
public |
Returns form values |
|
public |
Resets form without trigging the validation |