-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathinputSet.js
47 lines (37 loc) · 1.23 KB
/
inputSet.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
import React from 'react';
import FormFieldComponent from './formFieldComponent';
const labelStyle = { display: 'inline-block', width: 200 };
const setStyle = { paddingLeft: 20, border: '1px solid lightgray'};
export default class InputSet extends FormFieldComponent {
getDefaultValue() {
return {};
}
formValue(field, newValue) {
const value = {...this.state.value};
value[field] = newValue;
return value;
}
renderField(fieldConfig) {
const value = this.state.value;
return (
<div key={fieldConfig.field}>
<label style={labelStyle}>{fieldConfig.title}</label>
<fieldConfig.type
value={value ? value[fieldConfig.field] : null}
options={fieldConfig.options}
handleOnChange={this.handlOnChange.bind(this, fieldConfig.field)}
/>
</div>
);
}
render() {
if (!this.props.options || !this.props.options.fields) {
return null;
}
return (
<div style={setStyle} className="inputSet">
{this.props.options.fields.map(this.renderField.bind(this))}
</div>
);
}
}