Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
fix(conditional): use render instead of onChange to have access to form
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammer5 committed Aug 8, 2019
1 parent d622b34 commit 615488d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ const defaultMutators = {
clear,
}

export const Form = ({ children, mutators, ...props }) => {
export const Form = ({ mutators, ...props }) => {
return (
<RFFForm
{...props}
mutators={{
...defaultMutators,
...mutators,
}}
>
{children}
</RFFForm>
/>
)
}

Expand Down
6 changes: 5 additions & 1 deletion src/conditional.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export const conditional = Input => {
{condition && <Input {...props} />}

<FormSpy
onChange={({ form }) => {
render={({ form, values }) => {
if (!form.mutators.clear) return <Fragment />

if (!condition && values[props.name]) {
form.mutators.clear(props.name)
}

return <Fragment />
}}
/>
</Fragment>
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/translations.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"Required": ""
"Required": "",
"Not a valid e-mail": ""
}

0 comments on commit 615488d

Please sign in to comment.