-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathFieldInputArray.js
58 lines (55 loc) · 1.55 KB
/
FieldInputArray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React from 'react';
import PropTypes from 'prop-types';
import { Field } from 'redux-form'
import { FormGroup, ControlLabel, Button, Row, Col } from 'react-bootstrap';
import FieldInput from './FieldInput';
const FieldInputArray = ({ fields, config }) => {
return (
<div>
{
fields.map((field, index) => (
<div key={index}>
<Row>
<Col xs={6}>
<h3>{config.title} #{index + 1}</h3>
</Col>
<Col xs={6}>
<Button
className="button--remove"
type="button"
onClick={() => fields.remove(index)}
>
Remove {config.title}
</Button>
</Col>
</Row>
{
config.children.map((child, index) => (
<FormGroup key={index}>
<ControlLabel>{child.label}</ControlLabel>
<Field
name={`${field}.${child.property}`}
component={FieldInput}
type="text"
placeholder={child.label}
/>
</FormGroup>
))
}
</div>
))
}
<Button
className="button--add" type="button"
onClick={() => fields.push({})}
>
Add {config.title}
</Button>
</div>
)
};
FieldInputArray.propTypes = {
fields: PropTypes.object.isRequired,
config: PropTypes.object.isRequired,
};
export default FieldInputArray;