-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] Array field support #71
Comments
Hi @melloc01! I'm not exactly sure what your use case is. If possible, please provide code snippets or a live example to help me better understand this limitations (e.g. codesandbox). It sounds like For example, if you provide a custom component that controls const Requests = ({ onChange, validate, value }) => {
// maintaining the requests state independently
const [requests, setRequests] = useState(value);
const handleChange = useCallback((data) => {
// update the requests data how like
onChange(requests); // calling the input's onChange to update formState
});
return (
// logic to render and update the requests fields
);
}
const Form = () => {
const [formState, { text, raw }] = useFormState({ requests: [] });
return (
<>
<input {...text('name')} />
<Requests {...raw('requests')} formState={formState} />
</>
);
}; Keep in mind that validation errors can be anything (an object or an array) which will be useful if you want to have multiple errors for a single input. I hope that helps. |
That's cool, solved it. thanks @wsmd and sorry for the late reply. |
Let's say you have a field that is named:
Requests
:Is there a way to do something like this natively with the lib?
Of course, there are workarounds using 2 levels of
formState
:formState
perrow
and add a globalonChange
listener to change theformState
aboveraw
so you can triggeronChange
manually for the aboveformState
- this way you lose local validationI feel the lib could support these cases natively
Thanks in advance
The text was updated successfully, but these errors were encountered: