-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Deep form structure and deep validation #21
Comments
Your example of validator with my API suggestion: function contactValidation(data) {
const errors = {valid: true};
if(!data.name) {
errors.name = 'Required';
errors.valid = false;
}
if(data.address && data.address.length > 50) {
errors.address = 'Must be fewer than 50 characters';
errors.valid = false;
}
if(!data.phone) {
errors.phone = 'Required';
errors.valid = false;
} else if(!/\d{3}-\d{3}-\d{4}/.test(data.phone)) {
errors.phone = 'Phone must match the form "999-999-9999"';
errors.valid = false;
}
return errors;
} |
That seems perfectly reasonable. |
I see you done with validator API, thank you. |
Oh, does your library not bubble up the I don't think it's redux-form's responsibility to implement fancy validation. That should be up to the user of the library. |
I probably put it unclear. I talking about form data, not validation. Currenty createFormReducer('contacts', ['name', 'address', 'phone']) Do you have plans to support nested forms in |
Ah! I see. I'm not sure. When things get deep, you end up with complex schemas. Name-value pairs are so delightfully simple. If someone (you?) could come up with a good proposal for how to do deep forms that still allowed for a simple flat form api, I'd be willing to consider it. Nothing is springing immediately to mind, and most of my form needs are pretty flat. |
That's great. When I'll build next complex form I'll try to create PR with my solution. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi! Thank you for your library.
I want to use
redux-form
with complex deep structures. Simple example of complex structure I want to use:What are you think, is it possible to implement in
redux-form
?Also I have validator for complex deep structures.
I'm in deep refactoring right now, but I'll release a new version soon with async validation, simpler API, etc.
So, could you change API of validator from
({}) => {}
to something like that:And check only for
valid
property, not for every object key.With that API I could use my validation library with your form library.
The text was updated successfully, but these errors were encountered: