-
Notifications
You must be signed in to change notification settings - Fork 0
/
search-form.jsx
79 lines (59 loc) · 2.42 KB
/
search-form.jsx
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
import React from 'react';
import 'style.css';
import { Form, Button, Input, Radio, Select } from 'antd';
const Option = Select.Option;
const FormItem = Form.Item;
const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
class SearchForm extends React.Component {
onSubmit = (e) => {
e.preventDefault();
const {form, onSubmit} = this.props;
const vals = form.getFieldsValue();
//console.log('SearchForm Values:', vals);
onSubmit && onSubmit(vals);
}
render() {
const { form, items=[], style={}, hideSearchButton=false, children } = this.props;
const { getFieldDecorator } = form;
return (
<Form layout="inline" onSubmit={this.onSubmit} style={style} className="search-form">
{items.map(
({label, name, type, value, options, placeholder, style, onChange, className, ipt_style, dropdownMatchSelectWidth}, item_i)=>{
const item_key = '_s_f_'+item_i;
const ipt_attrs = { placeholder, onChange, style:ipt_style, dropdownMatchSelectWidth };
const item_attrs = { label, style, className /*className='ant-form-item-addon'设置label与表单为组*/ };
return (
<FormItem {...item_attrs} key={item_key}>
{getFieldDecorator(name, {
initialValue: value
})(
type=='Radios'?(
<RadioGroup {...ipt_attrs} options={options}/>
) : type=='RadioButtons'?(
<RadioGroup {...ipt_attrs} title={placeholder}>
{options.map(({value, label, attrs={}}, opt_i)=><RadioButton key={item_key+'_'+opt_i} value={value} {...attrs}>{label}</RadioButton>)}
</RadioGroup>
) : type=='Select'?(
<Select {...ipt_attrs}>
{options.map(({value, label, attrs={}}, opt_i)=><Option key={item_key+'_'+opt_i} value={value} {...attrs}>{label}</Option>)}
</Select>
) : (
<Input {...ipt_attrs} />
)
)}
</FormItem>
);
}
)}
{!hideSearchButton && <FormItem>
<Button type="primary" htmlType="submit" icon="search">
搜索
</Button>
</FormItem>}
{children&&<FormItem>{children}</FormItem>}
</Form>
);
}
}
export default Form.create()(SearchForm);