-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathinputArray.js
54 lines (41 loc) · 1.33 KB
/
inputArray.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
import React from 'react';
import FormFieldComponent from './formFieldComponent';
import TextField from './textField';
export default class InputArray extends FormFieldComponent {
getDefaultValue() {
return [];
}
formValue(index, newValue) {
const value = [...this.state.value];
value[index] = newValue;
return value;
}
onAddClick() {
let defaultValue = '';
if (this.props.options && this.props.options.getDefaultValue) {
defaultValue = this.props.options.getDefaultValue();
}
this.handlOnChange(this.state.value.length, defaultValue)
}
renderItem(itemValue, index) {
const value = this.props.value || [];
const options = this.props.options || {};
const Type = options.type ? options.type : TextField;
return (
<Type
key={index}
value={itemValue || null}
options={options.options}
handleOnChange={this.handlOnChange.bind(this, index)}
/>
);
}
render() {
return (
<div className="inputArray">
{this.state.value.map(this.renderItem.bind(this))}
<a href="javascript:void(0);" onClick={this.onAddClick.bind(this)}>Add</a>
</div>
);
}
}