-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathform.js
More file actions
128 lines (116 loc) · 3.8 KB
/
Copy pathform.js
File metadata and controls
128 lines (116 loc) · 3.8 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* eslint react/no-multi-comp:0, no-console:0 */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import TreeSelect from 'rc-tree-select';
import Select from 'rc-select';
import { createForm } from 'rc-form';
import 'rc-select/assets/index.css';
import 'rc-tree-select/assets/index.less';
import { regionStyle, errorStyle } from './styles';
import { gData } from './util';
import './demo.less';
const { Option } = Select;
class TreeSelectInput extends Component {
onChange = (value, ...args) => {
console.log(value, ...args);
const props = this.props;
if (props.onChange) {
props.onChange(value);
}
};
render() {
return <TreeSelect {...this.props} onChange={this.onChange} />;
}
}
// @createForm()
class Form extends Component {
static propTypes = {
form: PropTypes.object,
};
onSubmit = e => {
const { form } = this.props;
console.log('submit');
e.preventDefault();
form.validateFields((error, values) => {
if (!error) {
console.log('ok', values);
} else {
console.log('error', error, values);
}
});
};
reset = e => {
const { form } = this.props;
e.preventDefault();
form.resetFields();
};
render() {
const { form } = this.props;
const { getFieldDecorator, getFieldError } = form;
const tProps = {
multiple: true,
treeData: gData,
treeCheckable: true,
// treeDefaultExpandAll: true,
};
return (
<div style={{ margin: 20 }}>
<h2>validity</h2>
<form onSubmit={this.onSubmit}>
<div style={regionStyle}>
<div>
<p style={{ color: 'blue' }}>no onChange</p>
{getFieldDecorator('tree-select', {
initialValue: ['0-0-0-value'],
rules: [{ required: true, type: 'array', message: 'tree-select 需要必填' }],
})(<TreeSelect {...tProps} style={{ width: 300 }} />)}
</div>
<p style={errorStyle}>
{getFieldError('tree-select') ? getFieldError('tree-select').join(',') : null}
</p>
</div>
<div style={regionStyle}>
<div>
<p style={{ color: 'blue' }}>custom onChange</p>
{getFieldDecorator('tree-select1', {
initialValue: ['0-0-0-value'],
rules: [{ required: true, type: 'array', message: 'tree-select1 需要必填' }],
})(<TreeSelectInput {...tProps} style={{ width: 300 }} treeData={gData} />)}
</div>
<p style={errorStyle}>
{getFieldError('tree-select1') ? getFieldError('tree-select1').join(',') : null}
</p>
</div>
<div style={regionStyle}>
{getFieldDecorator('select', {
initialValue: 'jack',
rules: [{ required: true, type: 'array', message: 'select 需要必填' }],
})(
<Select style={{ width: 200 }} allowClear multiple>
<Option value="jack">jack</Option>
<Option value="lucy">lucy</Option>
<Option value="disabled" disabled>
disabled
</Option>
<Option value="yiminghe">yiminghe</Option>
</Select>,
)}
<p style={errorStyle}>
{getFieldError('select') ? getFieldError('select').join(',') : null}
</p>
</div>
<div style={regionStyle}>
<button type="button" onClick={this.reset}>
reset
</button>
<input type="submit" value="submit" />
</div>
</form>
</div>
);
}
}
// ReactDOM.render(<Form />, document.getElementById('__react-content'));
const NewForm = createForm()(Form);
export default () => <NewForm />;