Skip to content

Commit c5e421c

Browse files
committed
fix: add form wrappedComponentRef feature
1 parent 098e7ea commit c5e421c

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

components/_util/antRefDirective.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ export default {
44
bind: function (el, binding, vnode) {
55
binding.value(vnode)
66
},
7+
update: function (el, binding, vnode) {
8+
binding.value(vnode)
9+
},
710
unbind: function (el, binding, vnode) {
8-
binding.value()
11+
binding.value(null)
912
},
1013
})
1114
},

components/form/demo/advanced-search.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,16 @@ const AdvancedSearchForm = {
8888
const WrappedAdvancedSearchForm = Form.create()(AdvancedSearchForm)
8989
9090
export default {
91+
methods: {
92+
saveFormRef (inst) {
93+
this.formRef = inst
94+
console.log('formRef', this.formRef)
95+
},
96+
},
9197
render () {
9298
return (
9399
<div id='components-form-demo-advanced-search'>
94-
<WrappedAdvancedSearchForm />
100+
<WrappedAdvancedSearchForm wrappedComponentRef={(inst) => this.saveFormRef(inst)}/>
95101
<div class='search-result-list'>Search Result List</div>
96102
</div>
97103
)

components/form/index.en-US.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const CustomizedForm = {}
3030
CustomizedForm = Form.create({})(CustomizedForm);
3131
```
3232

33+
Maintain an ref for wrapped component instance, use `wrappedComponentRef`.
34+
Example: [demo](#components-form-demo-advanced-search)
35+
36+
3337
The following `options` are available:
3438

3539
| Property | Description | Type |
@@ -112,10 +116,10 @@ Note:
112116
| Property | Description | Type | Default Value |
113117
| -------- | ----------- | ---- | ------------- |
114118
| colon | Used with `label`, whether to display `:` after label text. | boolean | true |
115-
| extra | The extra prompt message. It is similar to help. Usage example: to display error message and prompt message at the same time. | string\|ReactNode | |
119+
| extra | The extra prompt message. It is similar to help. Usage example: to display error message and prompt message at the same time. | string\|slot | |
116120
| hasFeedback | Used with `validateStatus`, this option specifies the validation status icon. Recommended to be used only with `Input`. | boolean | false |
117-
| help | The prompt message. If not provided, the prompt message will be generated by the validation rule. | string\|ReactNode | |
118-
| label | Label text | string\|ReactNode | |
121+
| help | The prompt message. If not provided, the prompt message will be generated by the validation rule. | string\|slot | |
122+
| label | Label text | string\|slot | |
119123
| 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](/ant-design/components/grid/#Col) | |
120124
| required | Whether provided or not, it will be generated by the validation rule. | boolean | false |
121125
| validateStatus | The validation status. If not provided, it will be generated by validation rule. options: 'success' 'warning' 'error' 'validating' | string | |

components/form/index.zh-CN.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const CustomizedForm = {}
3030
CustomizedForm = Form.create({})(CustomizedForm);
3131
```
3232

33+
如果需要为包装组件实例维护一个ref,可以使用`wrappedComponentRef`
34+
参考[示例](#components-form-demo-advanced-search)
35+
36+
3337
`options` 的配置项如下。
3438

3539
| 参数 | 说明 | 类型 |
@@ -111,10 +115,10 @@ CustomizedForm = Form.create({})(CustomizedForm);
111115
| 参数 | 说明 | 类型 | 默认值 |
112116
| --- | --- | --- | --- |
113117
| colon | 配合 label 属性使用,表示是否显示 label 后面的冒号 | boolean | true |
114-
| extra | 额外的提示信息,和 help 类似,当需要错误信息和提示文案同时出现时,可以使用这个。 | string\|ReactNode | |
118+
| extra | 额外的提示信息,和 help 类似,当需要错误信息和提示文案同时出现时,可以使用这个。 | string\|slot | |
115119
| hasFeedback | 配合 validateStatus 属性使用,展示校验状态图标,建议只配合 Input 组件使用 | boolean | false |
116-
| help | 提示信息,如不设置,则会根据校验规则自动生成 | string\|ReactNode | |
117-
| label | label 标签的文本 | string\|ReactNode | |
120+
| help | 提示信息,如不设置,则会根据校验规则自动生成 | string\|slot | |
121+
| label | label 标签的文本 | string\|slot | |
118122
| labelCol | label 标签布局,同 `<Col>` 组件,设置 `span` `offset` 值,如 `{span: 3, offset: 12}``sm: {span: 3, offset: 12}` | [object](/ant-design/components/grid-cn/#Col) | |
119123
| required | 是否必填,如不设置,则会根据校验规则自动生成 | boolean | false |
120124
| validateStatus | 校验状态,如不设置,则会根据校验规则自动生成,可选:'success' 'warning' 'error' 'validating' | string | |

components/vc-form/src/createBaseForm.jsx

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ function createBaseForm (option = {}, mixins = []) {
9191
mounted () {
9292
this.wrappedComponentRef(this.$refs.WrappedComponent)
9393
},
94+
updated () {
95+
this.wrappedComponentRef(this.$refs.WrappedComponent)
96+
},
97+
destroyed () {
98+
this.wrappedComponentRef(null)
99+
},
94100
methods: {
95101
onCollectCommon (name, action, args) {
96102
const fieldMeta = this.fieldsStore.getFieldMeta(name)

0 commit comments

Comments
 (0)