forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.js
More file actions
76 lines (65 loc) · 2.39 KB
/
form.js
File metadata and controls
76 lines (65 loc) · 2.39 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from 'react';
import Form from '../../components/form';
const countriesArray = ['Spain', 'England', 'USA', 'Thailand', 'France'];
const countries = [
{ value: 'EN-gb', label: 'England', img: 'http://' },
{ value: 'ES-es', label: 'Spain', img: 'http://' },
{ value: 'TH-th', label: 'Thailand', img: 'http://' },
{ value: 'EN-en', label: 'USA', img: 'http://' },
{ value: 'FR-fr', label: 'France', img: 'http://' }
];
const FormFields = {
autocomplete: {kind: 'Autocomplete', label: 'Autocomplete', source: countriesArray, value: ''},
input: {kind: 'Input', type: 'text', label: 'Input', value: '@soyjavi', required: true},
multiline: {kind: 'Input', type: 'text', label: 'Input (multiline)', multiline: true},
number: {kind: 'Input', type: 'number', label: 'Input (number)'},
checkbox: {kind: 'Checkbox', label: 'Checkbox'},
date: {kind: 'DatePicker', label: 'DatePicker', value: undefined},
dropdown: {kind: 'Dropdown', label: 'Dropdown', source: countries, value: countries[2].value},
time: {kind: 'TimePicker', label: 'TimePicker', value: undefined},
switch: {kind: 'Switch', label: 'Switch'},
slider: {kind: 'Slider', label: 'Slider', min: 0, max: 10, value: 4, pinned: true},
submit: {kind: 'Button', type: 'submit', label: 'Button () you a nomad?'}
};
class FormTest extends React.Component {
state = {
model: {
autocomplete: countriesArray[3],
input: 'soyjavi',
multiline: 'Overwritten',
number: 0,
checkbox: true
}
};
handleEvent = (type, event, form) => {
console.log(`[FORM.${type}]`, event, form);
};
handleChange = (field, value) => {
console.log('FORM.change', field, value);
const model = {
...this.state.model,
[field]: value
};
this.setState({ model });
};
render () {
Object.keys(this.state.model).map((field) => {
const formField = FormFields[field];
formField[formField.hasOwnProperty('value') ? 'value' : 'checked'] = this.state.model[field];
});
console.log(FormFields);
return (
<section>
<h5>Form</h5>
<p>lorem ipsum...</p>
<Form
model={FormFields}
onChange={this.handleChange}
onError={this.handleEvent.bind(this, 'error')}
onValid={this.handleEvent.bind(this, 'valid')}
onSubmit={this.handleEvent.bind(this, 'submit')} />
</section>
);
}
}
export default FormTest;