FormSection validation, how to handle?
See original GitHub issueIs there a way to add validation (Sync) at FormSection level? If we consider the example below, i wish i could use the validation system on the address component level. It might not be a good idea, what would you suggest then to deal with nested object models and validation
const renderField = ({ input, label, type, meta: { touched, error, warning } }) => (
<div>
<label>{label}</label>
<div>
<input {...input} placeholder={label} type={type}/>
{touched && ((error && <span>{error}</span>) || (warning && <span>{warning}</span>))}
</div>
</div>
)
class Address extends FormSection {
// I need to validate this section ! Is there a Redux-From build-in solution ?
render(){
return (
<div>
<Field name="street" type="text" component={renderField} label="Street"/>
<Field name="city" type="text" component={renderField} label="City"/>
<Field name="zipCode" type="text" component={renderField} label="Zip Code"/>
<Field name="country" type="text" component={renderField} label="Country"/>
</div>
);
}
}
const validate = values => {
// do the validation for the CustomerForm (only the name field)
}
const CustomerForm = (props) => {
const { handleSubmit, pristine, reset, submitting } = props
return (
<form onSubmit={handleSubmit}>
<Field name="name" type="text" component={renderField} label="Name"/>
<Address name={'delivery'} />
</form>
}
}
export default reduxForm({
form: 'customer', // Form name
fields: [ 'name', 'address' ], // Form fields
validate // <--- Validation function
})(CustomerForm);
Thank you for your help and advices
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:7 (1 by maintainers)
Top Results From Across the Web
FormSection validation, how to handle? · Issue #2150 - GitHub
There isn't FormSection level validation, but it's pretty straightforward to create a validation function for your Address component, ...
Read more >Using Validation on a FormSection with Redux Forms
As a workaround, you can use form-level validation: ... your validation function, field names will be prefixed with the FormSection's name.
Read more >Synchronous Validation Example - Redux Form
There are two ways to provide synchronous client-side validation to your form. The first is to provide redux-form with a validation function that...
Read more >Examples - Final Form Docs
Demonstrates how to use React Final Form to create a multi-page "wizard" form, with validation on each page. Parse and Format (and Normalize)....
Read more >ASP.NET Core Blazor forms and input components
You can create custom validator components to process validation ... from the Example form section is used that only accepts the starship's ...
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
Is this still true? While you’re correct that it can be added at the form level, I’ve modularized my components into Fields and FormSections for reusability and I wish I could encapsulate validation in my FormSection components just like in my Field components.
Hi @lnhrdt, yes, this still holds true. A suggestion I can make you for now is to export the validation functions for each section/field and compose them together.
Here you go, for some good ideas: https://github.com/jfairbank/revalidate