MCPcopy Create free account
hub / github.com/Lobos/react-ui / constructor

Method constructor

src/Form.js:17–77  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

15
16class Form extends Component {
17 constructor (props) {
18 super(props);
19 this.state = {
20 data: props.data
21 };
22
23 this.handleSubmit = this.handleSubmit.bind(this);
24 this.submit = this.submit.bind(this);
25
26 this.items = {};
27 this.validationPools = {};
28
29 this.itemBind = (item) => {
30 this.items[item.id] =item;
31
32 let data = this.state.data;
33 data[item.name] = item.value;
34 this.setState({ data });
35
36 // bind triger item
37 if (item.valiBind) {
38 item.valiBind.forEach((vb) => {
39 this.validationPools[vb] = (this.validationPools[vb] || []).concat(item.validate);
40 });
41 }
42 };
43
44 this.itemUnbind = (id, name) => {
45 let data = this.state.data;
46 delete this.items[id];
47 delete data[name];
48 // remove valiBind
49 delete this.validationPools[name];
50 this.setState({ data });
51 };
52
53 this.itemChange = (id, value, err) => {
54 let data = this.state.data;
55 const name = this.items[id].name;
56
57 // don't use merge or immutablejs
58 //data = merge({}, data, {[name]: value});
59
60 if (data[name] !== value) {
61 data[name] = value;
62 // setState only triger render, data was changed
63 this.setState({ data });
64 }
65
66 let valiBind = this.validationPools[name];
67 if (valiBind) {
68 valiBind.forEach((validate) => {
69 if (validate) {
70 validate();
71 }
72 });
73 }
74

Callers

nothing calls this directly

Calls 1

validateFunction · 0.50

Tested by

no test coverage detected