Skip to content

Commit 3a3eec6

Browse files
committed
From 组件新增 labelCol、wrapperCol
1 parent 56b1da5 commit 3a3eec6

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

components/form/Form.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PropTypes from '../_util/vue-types';
22
import classNames from 'classnames';
3+
import { ColProps } from '../grid/Col';
34
import Vue from 'vue';
45
import isRegExp from 'lodash/isRegExp';
56
import warning from '../_util/warning';
@@ -59,6 +60,8 @@ export const WrappedFormUtils = {
5960

6061
export const FormProps = {
6162
layout: PropTypes.oneOf(['horizontal', 'inline', 'vertical']),
63+
labelCol: PropTypes.shape(ColProps).loose,
64+
wrapperCol: PropTypes.shape(ColProps).loose,
6265
form: PropTypes.object,
6366
// onSubmit: React.FormEventHandler<any>;
6467
prefixCls: PropTypes.string,

components/form/FormItem.jsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ export default {
314314
},
315315

316316
renderWrapper(prefixCls, children) {
317-
const { wrapperCol = {} } = this;
317+
const { FormProps: { wrapperCol: wrapperColForm = {} } = {} } = this;
318+
const { wrapperCol = wrapperColForm } = this;
318319
const { class: cls, style, id, on, ...restProps } = wrapperCol;
319320
const className = classNames(`${prefixCls}-item-control-wrapper`, cls);
320321
const colProps = {
@@ -369,7 +370,8 @@ export default {
369370
},
370371

371372
renderLabel(prefixCls) {
372-
const { labelCol = {}, colon, id } = this;
373+
const { FormProps: { labelCol: labelColForm = {} } = {} } = this;
374+
const { labelCol = labelColForm, colon, id } = this;
373375
const label = getComponentFromProp(this, 'label');
374376
const required = this.isRequired();
375377
const {

components/form/demo/validate-other.vue

+13-17
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Demonstration of validation configuration for form controls which are not shown
99
</us>
1010

1111
<template>
12-
<a-form id="components-form-demo-validate-other" :form="form" @submit="handleSubmit">
13-
<a-form-item v-bind="formItemLayout" label="Plain Text">
12+
<a-form id="components-form-demo-validate-other" :form="form" v-bind="formItemLayout" @submit="handleSubmit">
13+
<a-form-item label="Plain Text">
1414
<span class="ant-form-text">
1515
China
1616
</span>
1717
</a-form-item>
18-
<a-form-item v-bind="formItemLayout" label="Select" has-feedback>
18+
<a-form-item label="Select" has-feedback>
1919
<a-select
2020
v-decorator="[
2121
'select',
@@ -32,7 +32,7 @@ Demonstration of validation configuration for form controls which are not shown
3232
</a-select>
3333
</a-form-item>
3434

35-
<a-form-item v-bind="formItemLayout" label="Select[multiple]">
35+
<a-form-item label="Select[multiple]">
3636
<a-select
3737
v-decorator="[
3838
'select-multiple',
@@ -57,25 +57,25 @@ Demonstration of validation configuration for form controls which are not shown
5757
</a-select>
5858
</a-form-item>
5959

60-
<a-form-item v-bind="formItemLayout" label="InputNumber">
60+
<a-form-item label="InputNumber">
6161
<a-input-number v-decorator="['input-number', { initialValue: 3 }]" :min="1" :max="10" />
6262
<span class="ant-form-text">
6363
machines
6464
</span>
6565
</a-form-item>
6666

67-
<a-form-item v-bind="formItemLayout" label="Switch">
67+
<a-form-item label="Switch">
6868
<a-switch v-decorator="['switch', { valuePropName: 'checked' }]" />
6969
</a-form-item>
7070

71-
<a-form-item v-bind="formItemLayout" label="Slider">
71+
<a-form-item label="Slider">
7272
<a-slider
7373
v-decorator="['slider']"
7474
:marks="{ 0: 'A', 20: 'B', 40: 'C', 60: 'D', 80: 'E', 100: 'F' }"
7575
/>
7676
</a-form-item>
7777

78-
<a-form-item v-bind="formItemLayout" label="Radio.Group">
78+
<a-form-item label="Radio.Group">
7979
<a-radio-group v-decorator="['radio-group']">
8080
<a-radio value="a">
8181
item 1
@@ -89,7 +89,7 @@ Demonstration of validation configuration for form controls which are not shown
8989
</a-radio-group>
9090
</a-form-item>
9191

92-
<a-form-item v-bind="formItemLayout" label="Radio.Button">
92+
<a-form-item label="Radio.Button">
9393
<a-radio-group v-decorator="['radio-button']">
9494
<a-radio-button value="a">
9595
item 1
@@ -103,7 +103,7 @@ Demonstration of validation configuration for form controls which are not shown
103103
</a-radio-group>
104104
</a-form-item>
105105

106-
<a-form-item v-bind="formItemLayout" label="Checkbox.Group">
106+
<a-form-item label="Checkbox.Group">
107107
<a-checkbox-group
108108
v-decorator="['checkbox-group', { initialValue: ['A', 'B'] }]"
109109
style="width: 100%;"
@@ -138,15 +138,11 @@ Demonstration of validation configuration for form controls which are not shown
138138
</a-checkbox-group>
139139
</a-form-item>
140140

141-
<a-form-item v-bind="formItemLayout" label="Rate">
141+
<a-form-item label="Rate">
142142
<a-rate v-decorator="['rate', { initialValue: 3.5 }]" allow-half />
143143
</a-form-item>
144144

145-
<a-form-item
146-
v-bind="formItemLayout"
147-
label="Upload"
148-
extra="longgggggggggggggggggggggggggggggggggg"
149-
>
145+
<a-form-item label="Upload" extra="longgggggggggggggggggggggggggggggggggg">
150146
<a-upload
151147
v-decorator="[
152148
'upload',
@@ -163,7 +159,7 @@ Demonstration of validation configuration for form controls which are not shown
163159
</a-upload>
164160
</a-form-item>
165161

166-
<a-form-item v-bind="formItemLayout" label="Dragger">
162+
<a-form-item label="Dragger">
167163
<div class="dropbox">
168164
<a-upload-dragger
169165
v-decorator="[

components/form/index.en-US.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
| form | Decorated by `Form.create()` will be automatically set `this.form` property, so just pass to form. If you use the template syntax, you can use `this.$form.createForm(this, options)` | object | n/a |
88
| hideRequiredMark | Hide required mark of all form items | Boolean | false |
99
| layout | Define form layout | 'horizontal'\|'vertical'\|'inline' | 'horizontal' |
10+
| labelCol | The layout of label. You can set `span` `offset` to something like `{span: 3, offset: 12}` or `sm: {span: 3, offset: 12}` same as with `<Col>` | [object](/components/grid/#Col) | |
11+
| wrapperCol | The layout for input controls, same as `labelCol` | [object](/components/grid/#Col) | |
1012
| autoFormCreate(deprecated) | Automate Form.create, Recommended for use under the `template` component, and cannot be used with `Form.create()`. You should use `$form.createForm` to instead it after 1.1.9. | Function(form) | |
1113
| options(deprecated) | The `options` corresponding to `Form.create(options)`. You should use `$form.createForm` to instead it after 1.1.9. | Object | {} |
1214

components/form/index.zh-CN.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
| form |`Form.create()` 包装过的组件会自带 `this.form` 属性,如果使用 template 语法,可以使用 this.\$form.createForm(this, options) | object ||
88
| hideRequiredMark | 隐藏所有表单项的必选标记 | Boolean | false |
99
| layout | 表单布局 | 'horizontal'\|'vertical'\|'inline' | 'horizontal' |
10+
| labelCol | label 标签布局,同 `<Col>` 组件,设置 `span` `offset` 值,如 `{span: 3, offset: 12}``sm: {span: 3, offset: 12}` | [object](/components/grid-cn/#Col) | |
11+
| wrapperCol | 需要为输入控件设置布局样式时,使用该属性,用法同 labelCol | [object](/components/grid-cn/#Col) | |
1012
| selfUpdate | 自定义字段更新逻辑,说明[见下](/components/form-cn/#selfUpdate),需 1.3.17 版本以上 | boolean | false |
1113

1214
### 事件

0 commit comments

Comments
 (0)