Form.js
1.45 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
import template from "./Form.html";
import style from "antd/lib/form/style/index.css";
class Form {
useModules = ["esNgAntd"];
template = template;
props = {
name: String,
labelCol: Object,
wrapperCol: Object,
onFinish: Function,
form: Object,
};
state = {
formItems: [],
};
constructor() {
esNgAntd.createStyle("ant-form", style);
if (this.form !== undefined) {
this.form = $scope;
}
if (this.props.name) {
let inputs = $element[0].querySelectorAll("input");
for (let i = 0; i < inputs.length; i++) {
const element = inputs[i];
element.id = this.props.name + "_" + element.id;
}
}
}
resetFields() {
this.state.formItems.forEach(function (item) {
if (typeof item.setValue === "function") {
item.setValue(item.defaultValue || null);
} else {
item.value = null;
}
});
}
submit() {
this.handleSubmit();
}
handleSubmit() {
let values = {};
this.state.formItems.forEach(function (item) {
let name = item.antdFormItem && item.antdFormItem.name;
let value = item.value || item.state.value || null;
values[name] = value;
});
this.props.onFinish({
values: values,
});
}
}