christianalfoni / formsy-react

A form input builder and validator for React JS
MIT License
2.6k stars 438 forks source link

One component with multiple instance #464

Closed attiqeurrehman closed 6 years ago

attiqeurrehman commented 6 years ago

Hi,

I have component Address which will be used in a long form at least twice. Something like this:

<Formsy.Form>
        <Address name="employeeAddress"/>
        <Address name="studentAddress"/> 
</Formsy.Form>

But on form submit I only get one address object in the model.

capture

I want it to display both with different names employeeAddress and studentAddress.

Thanks, Attiqe

attiqeurrehman commented 6 years ago

I was able to do it by getting the name of prop in render function and then adding it with the component.

var componentName = this.props.name;
<Formsy.Input
                            name={componentName + '.country'}
                            value=""
                            type="text"
                            placeholder="Country/Region" />