I am trying to create a way for a user to multiply their form.
A user may add several "Name"/"Number" at one time. But they will only add it under one "Area"
How do I create a form where I can "duplicate" the input fields?
It will, in a way, simply "copy" the form so you can enter the data again.
This screenshot should explain:
I've also put it in a code pen:
http://codepen.io/yarnball/pen/qaQomG?editors=1010
var Postapi = React.createClass({
getInitialState: function() {
return {
area:'',
name: '',
number: '',
};
},
onChange(e) {
this.setState({[e.target.name]: e.target.value})
},
handleSubmit: function(e) {
e.preventDefault();
return fetch('http://localhost:8000/api/Data/', {
method: 'POST',
body: JSON.stringify({
area: this.state.area,
info:[
{name:this.state.name,
taglevel:this.state.number}
],
})
})
.then(function(res){ return res.json(); })
.then(function(data){ alert( JSON.stringify( data ) ) })
},
render: function() {
return (
<form onSubmit={this.handleSubmit}>
<input
name="area"
type="text"
placeholder="Area"
onChange={this.onChange}
/>
<input
name="name"
type="text"
placeholder="Name"
onChange={this.onChange}
/>
<input
name="number"
type="text"
placeholder="Number"
onChange={this.onChange}
/>
<button type="submit">Submit</button>
</form>
);
}
});

redux-formif you are not planning to write yet another lib.