Releases: knightburton/react-use-form
v1.2.0
Add stopPropagation call on submit if event available.
Add stopPropagationEventOnSubmit option to enable/disable this functionality (enabled by default).
Example:
const { fields, handleChange, handleSubmit } = useForm<IForm>({
schema: [],
onSubmit: () => {},
stopPropagationEventOnSubmit: false,
});v1.1.0
Functionality upgrade:
Add the possibility to the required property on the schema to consume a special Validator.
So the check and error handling could be done in one place with own logic both on the rule and error.
Example:
const schema = [
{
field: 'example',
value: '',
required: {
rule: (value, fields) => value === fields['randomOtherField'],
error: value => `This "${value}" is bad for you...`,
}
},
{
field: 'randomOtherField',
value: 'bad',
},
];v1.0.3
This patch fix the unnecessary inner state (as fields) arg on the requiredError handler function and validator rules handler. Now the fields are contains only the final key value pairs.
Example from before state:
validators: [{ rule: (value, fields) => value !== fields.someOtherField.value, error: 'This is not good...' }]Example with this patch:
validators: [{ rule: (value, fields) => value !== fields.someOtherField, error: 'This is not good...' }]v1.0.2
Export base types that needs to create the options, schema or handler functions.
v1.0.1
This patch make sure the returned object for the onSubmit handler is only contains the fields state as key value pairs in case of a successful validation.
For example if the state looks like this:
{
title: { value: 'A nice title', error: '' },
description: { value: 'Lorem ipsum...', error: '' }
}Then the returned object will be like this:
{
title: 'A nice title',
description: 'Lorem ipsum...',
}v1.0.0
Initial release of the project.