How to use validator to validate Form.List on Antd
This is my form, how to make sure this form is filled with at least 1 data
2 Replies
Hi @regn. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To ensure that the Form.List is filled with at least one bank account entry, you can add a validation rule to the Form.List itself. Here's how you can modify your code to achieve this:
The key change here is the addition of the
rules
prop to the Form.List
component. We've added a custom validator that checks if the value (which is an array of bank accounts) exists and has at least one entry. If not, it rejects with an error message.
This approach is based on the custom validation technique described in the Refine documentation for Ant Design forms Custom Form Validation (https://refine.dev/docs/examples/form/antd/custom-form-validation/).
By adding this validation rule, the form will require at least one bank account to be added before it can be submitted successfully. The error message will be displayed if the user tries to submit the form without adding any bank accounts.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@336843331416096768> Kapa.ai is still learning and improving, please let me know how I did by reacting below.