forked from alibaba/ice
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleFormDialog.jsx
More file actions
157 lines (146 loc) · 3.99 KB
/
SimpleFormDialog.jsx
File metadata and controls
157 lines (146 loc) · 3.99 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import React, { Component } from 'react';
import { Dialog, Grid, Input, Radio, Button } from '@icedesign/base';
import IceContainer from '@icedesign/container';
import {
FormBinderWrapper as IceFormBinderWrapper,
FormBinder as IceFormBinder,
FormError as IceFormError,
} from '@icedesign/form-binder';
const { Row, Col } = Grid;
const { Group: RadioGroup } = Radio;
const defaultValue = {
keywords: '',
type: 'post',
content: '',
};
export default class SimpleFormDialog extends Component {
static displayName = 'SimpleFormDialog';
constructor(props) {
super(props);
this.state = {
visible: false,
value: defaultValue,
};
}
showDialog = () => {
this.setState({
visible: true,
});
};
hideDialog = () => {
this.setState({
visible: false,
});
};
onOk = () => {
this.refForm.validateAll((error) => {
if (error) {
// show validate error
return;
}
// deal with value
this.hideDialog();
});
};
onFormChange = (value) => {
this.setState({
value,
});
};
render() {
return (
<IceContainer>
<Dialog
className="simple-form-dialog"
style={styles.simpleFormDialog}
autoFocus={false}
footerAlign="center"
title="简单表单"
{...this.props}
onOk={this.onOk}
onCancel={this.hideDialog}
onClose={this.hideDialog}
isFullScreen
visible={this.state.visible}
>
<IceFormBinderWrapper
ref={(ref) => {
this.refForm = ref;
}}
value={this.state.value}
onChange={this.onFormChange}
>
<div style={styles.dialogContent}>
<Row style={styles.formRow}>
<Col span="3">
<label style={styles.formLabel}>关键词</label>
</Col>
<Col span="16">
<IceFormBinder
required
min={2}
max={10}
message="当前字段必填,且最少 2 个字最多 10 个字"
>
<Input
name="keywords"
style={styles.input}
placeholder="多关键词用英文 , 号分割"
/>
</IceFormBinder>
<IceFormError name="keywords" />
</Col>
</Row>
<Row style={styles.formRow}>
<Col>
<IceFormBinder>
<RadioGroup
name="type"
dataSource={[
{
value: 'post',
label: '文章',
},
{
value: 'video',
label: '视频',
},
{
value: 'image',
label: '图片',
},
]}
/>
</IceFormBinder>
</Col>
</Row>
<Row style={styles.formRow}>
<Col>
<IceFormBinder>
<Input
name="content"
style={styles.input}
multiple
placeholder="请输入详细内容"
rows={4}
/>
</IceFormBinder>
</Col>
</Row>
</div>
</IceFormBinderWrapper>
</Dialog>
<Button type="primary" onClick={this.showDialog}>
显示 Dialog
</Button>
</IceContainer>
);
}
}
const styles = {
simpleFormDialog: { width: '640px' },
dialogContent: {},
formRow: { marginTop: 20 },
input: { width: '100%' },
formLabel: { lineHeight: '26px' },
};