-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Labels
Milestone
Description
Environment
- react-advanaced-form: 1.6.0
What
Current behavior
When a field with the reactive required
prop changes its value to false
, the subscriber field is still validated to invalid: true
.
Expected behavior
A field with reactive prop (i.e. required
) must be validated properly when the reactive prop value toggles.
Why
- Validation originating from reactive resolver is
forced: true
- Thus,
shouldValidateSync
predicate resolves totrue
- Thus, relevant
rules.type.tel
rule is executed on an empty field - Resulting into invalid field from the validation.
The reason is that the validation resolver is invoked when it shouldn't. The relation with the forced nature of reactive validation is not correct.
How
import React from 'react'
import { Form } from 'react-advanced-form'
import { Input, Checkbox } from '@examples/fields'
const rules = {
type: {
tel: ({ value }) => /^\+420/.test(value),
},
}
export default class FooExample extends React.Component {
render() {
return (
<Form rules={rules}>
<Input
type="tel"
name="phone"
label="Phone"
required={({ get }) => get(['some', 'checked'])}
/>
<Checkbox name="some" label="Accept" />
</Form>
)
}
}
Thank you notes to @ludovitkapusta for reporting this issue.