score:1
I figured this out - it wasn't showing the errors because the Form.Item in the TextInput was checking for the field to be touched first:
<Form.Item
label={label}
hasFeedback={!!errors[name]}
validateStatus={touched[name] && errors[name] && 'error'}
help={touched[name] && errors[name]}
>
...changing this to the following allows this to work (I just remove the check for whether the field was actually touched):
<Form.Item
label={label}
hasFeedback={!!errors[name]}
validateStatus={errors[name] && 'error'}
help={errors[name]}
>
score:0
Yes, you can validate for button click instead form submit. Some points you should consider.
- You should wrap the form elements with tag.
Don't forget to use the export method wrap with create form method.
export default Form.create()(SimpleForm
);add a onlick method and use validate method like below.
this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { //Do something what you want. } });
Use proper validation method for fields
Good luck!
score:0
On validate all button click, you could use form.submitForm();
You can check here with working stackblitz demo.
Code snippet
function doSave(values) {
console.log("saving data", values);
}
function validateAllClick(form) {
form.submitForm();
console.log("just validating");
}
function App() {
return (
<Layout>
<h1>Here's My Form</h1>
<Content>
<CreateItemForm
status={editModelStatus}
setFormRef={setFormRef}
onSubmit={values => doSave(values)}
onValidate={validateAllClick}
/>
</Content>
</Layout>
);
}
Source: stackoverflow.com
Related Query
- Cannot get validation only to fire for Antd form with Formik - errored fields only show when actually trying to submit
- React Formik - Trigger validation only on form submit
- Formik & yup form validation not working as expected with VirtualizedSelect
- Cannot get Material UI radio buttons to work with Formik
- How to get values from react FieldArray in formik form with other fields?
- Formik React with 2 buttons (Submit and Save) to submit form - Save button not to trigger validation
- How to create dynamic form input fields in React with ANTd
- Yup validation for nested form elements in formik
- How to integrate redux with antd form validation
- Validation works incorrectly for React-select with Formik on mobile device
- Disable button till all the form fields get filled in Formik
- React, Formik and implementing Repeatable Form Fields (as forms with multiple fields)
- How do I get onChange to work with several form fields in Reactjs?
- yup form validation with formik using regex not working as expected with bangla font input field
- Validation accept only two specific fields the selector with yup
- formik form validation with regular expressions
- How to get the value of Antd Form with React Hooks?
- Antd 3.26 form validation messages are not rerendering with new value when state/props are changing
- How to trim textarea and prevent the form to be sent with whitespaces only Formik
- Validation at form level on multiple fields with Yup and react-hook-form
- Validation for array of fields using react hook form
- Validation 2 fields with yup and formik
- How do I implement a functional so that you can interact with the form only once for each user?
- Cannot get initial value for the input select form
- Hapi route validation with Joi for Form Data
- How to get the Yup conditional validation to work with Formik in Reactjs?
- React scroll with antd tabs (scrollIntoView) working for some tabs only
- Can't get formik validation to work with react-router
- What are the typings for multi-page or multi-step formik form with React Hooks?
- How to add validations for formik form with material UI
More Query from same tag
- React DnD: Avoid using findDOMNode
- Sinon FakeServer no requests?
- Form Validation not working using react and StepWizard
- How to prepending before icon for text area for React component
- How to sort or create a new array by grouping year and data
- how to do Storybook React Material UI custom styling
- React: How to assign key based on state counter and increment state counter in mapping?
- React error saying Objects are not valid as react child
- How to access props in a functional HOC?
- Can't save createdAt and updatedAt as datetime values nor backend neither frontend
- how to update records after drag and drop
- React + Webpack: React.createElement: type should not be null, undefined, boolean, or number
- Warning when passing a function to a wrapped component prop
- React: Invalid hook call in SubmitForm, custom hook useSendFormData
- Clicking a left arrow or a right arrow to switch an element in an array with the element on the left or right React
- state not updating after AJAX call using setState()
- Not able to get values from Redux to props
- How can I destructure a React prop and still access other props?
- How to type custom React hooks that are created in JS and used in a TSX file?
- Playing local mp3 files with react js without importing
- Passing data from JSON to React component Apexchart timeline
- Clear imported CSS
- Next-Slicezone 'module parse failed' when using with Prismic.io
- how to do custom global filtering on the react table
- Passing current element to onClick function - React Jsx
- add language to header using axios
- How to render value in class based react
- What is the idiomatic ReactJS way to deal with ?initial? state?
- How to call two arrow functions onclick ReactJS
- Swap objects in array with react immutability helper