File tree 3 files changed +36
-2
lines changed
3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -139,16 +139,45 @@ const Form = {
139
139
createForm ( context , options = { } ) {
140
140
return new Vue ( Form . create ( { ...options , templateContext : context } ) ( ) ) ;
141
141
} ,
142
+ created ( ) {
143
+ this . formItemContexts = new Map ( ) ;
144
+ } ,
142
145
provide ( ) {
143
146
return {
144
147
FormProps : this . $props ,
148
+ // https://github.com/vueComponent/ant-design-vue/issues/446
149
+ collectFormItemContext :
150
+ this . form && this . form . templateContext
151
+ ? ( c , type = 'add' ) => {
152
+ const formItemContexts = this . formItemContexts ;
153
+ const number = formItemContexts . get ( c ) || 0 ;
154
+ if ( type === 'delete' ) {
155
+ if ( number <= 1 ) {
156
+ formItemContexts . delete ( c ) ;
157
+ } else {
158
+ formItemContexts . set ( c , number - 1 ) ;
159
+ }
160
+ } else {
161
+ if ( c !== this . form . templateContext ) {
162
+ formItemContexts . set ( c , number + 1 ) ;
163
+ }
164
+ }
165
+ }
166
+ : ( ) => { } ,
145
167
} ;
146
168
} ,
147
169
watch : {
148
170
form ( ) {
149
171
this . $forceUpdate ( ) ;
150
172
} ,
151
173
} ,
174
+ beforeUpdate ( ) {
175
+ this . formItemContexts . forEach ( ( number , c ) => {
176
+ if ( c . $forceUpdate ) {
177
+ c . $forceUpdate ( ) ;
178
+ }
179
+ } ) ;
180
+ } ,
152
181
updated ( ) {
153
182
if ( this . form && this . form . cleanUpUselessFields ) {
154
183
this . form . cleanUpUselessFields ( ) ;
@@ -232,7 +261,6 @@ const Form = {
232
261
/>
233
262
) ;
234
263
}
235
-
236
264
return (
237
265
< form onSubmit = { onSubmit } class = { formClassName } >
238
266
{ $slots . default }
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import BaseMixin from '../_util/BaseMixin';
19
19
import { cloneElement , cloneVNodes } from '../_util/vnode' ;
20
20
import Icon from '../icon' ;
21
21
22
+ function noop ( ) { }
22
23
export const FormItemProps = {
23
24
id : PropTypes . string ,
24
25
prefixCls : PropTypes . string ,
@@ -47,10 +48,15 @@ export default {
47
48
inject : {
48
49
FormProps : { default : { } } ,
49
50
decoratorFormProps : { default : { } } ,
51
+ collectFormItemContext : { default : ( ) => noop } ,
50
52
} ,
51
53
data ( ) {
54
+ this . collectFormItemContext ( this . $vnode . context ) ;
52
55
return { helpShow : false } ;
53
56
} ,
57
+ beforeDestroy ( ) {
58
+ this . collectFormItemContext ( this . $vnode . context , 'delete' ) ;
59
+ } ,
54
60
mounted ( ) {
55
61
warning (
56
62
this . getControls ( this . slotDefault , true ) . length <= 1 ,
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ function createBaseForm(option = {}, mixins = []) {
56
56
data ( ) {
57
57
const fields = mapPropsToFields && mapPropsToFields ( this . $props ) ;
58
58
this . fieldsStore = createFieldsStore ( fields || { } ) ;
59
-
59
+ this . templateContext = templateContext ;
60
60
this . instances = { } ;
61
61
this . cachedBind = { } ;
62
62
this . clearedFieldMetaCache = { } ;
You can’t perform that action at this time.
0 commit comments