Prevent field validation on form mount
See original GitHub issuebug report/feature request
What is the current behavior?
field validation runs on mount of form
<Field
name="investorEmail"
validateFields={[]}
component={TextInput}
type="email"
withWrapper
hint=""
label="Investors e-mail address"
validate={(value) => validateRequiredEmail(value, 'investorEmail', 3)}
/>
the field behaves correctly, when error is not collected through
error={this.props.error || this.props.meta?.error}
but only this.props.error
, but I would like not to have these hacks in my code. Is there elegant solution?
What is the expected behavior?
prevent validation from running on the first render
can be acomplished by
validate={(value, values, meta) => meta.touched && validateRequiredEmail(value, ‘investorEmail’, 3)} , but then doesn’t validate on form submit
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
How to disable validation on form reset react-final-form?
I have custom validation in email input field, which is being triggered by form.reset() , which reset the form (After user successfully ...
Read more >Handling Forms - VeeValidate
This will prevent submitting the form until all fields are valid. Using validate(). You can validate the form without submissions using the validate()...
Read more >useForm - unregister - React Hook Form
This method allows you to unregister a single input or an array of inputs. ... By unregister an input, it will not affect...
Read more >Form - Ant Design
High performance Form component with data scope management. Including data collection, verification, ... When you need to validate fields in certain rules.
Read more >Synchronous Validation Example - Redux Form
IMPORTANT: In your validate function, values can be undefined , so pay attention when you are validating nested fields. If not, you could...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I came here trying to find out how to prevent a
FormSpy
to callonChange
on mount. I ended using lodashisEmpty
together with thetouched
value of the form since it will always be an empty object on the first render to prevent saving the formI typically only validate if a value is present.