Skip to content

Commit f05cb6b

Browse files
authored
fix(core): fix void field child field reactions not work in some cases (#3415)
* feat: set Form indexes observable * feat: add test cases
1 parent b3d3eb7 commit f05cb6b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/core/src/__tests__/void.spec.ts

+41
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,44 @@ test('fault tolerance', () => {
285285
expect(field.display).toEqual('visible')
286286
expect(field.pattern).toEqual('editable')
287287
})
288+
289+
test('child field reactions', () => {
290+
const form = attach(createForm())
291+
const voidField = attach(form.createVoidField({ name: 'void' }))
292+
const field1 = attach(
293+
form.createField({
294+
name: 'field1',
295+
basePath: voidField.address,
296+
reactions: [
297+
(field) => {
298+
field.value = field.query('field3').getIn('value')
299+
},
300+
],
301+
})
302+
)
303+
const field2 = attach(
304+
form.createField({
305+
name: 'field2',
306+
basePath: voidField.address,
307+
reactions: [
308+
(field) => {
309+
field.value = field.query('.field3').getIn('value')
310+
},
311+
],
312+
})
313+
)
314+
expect(field1.value).toBeUndefined()
315+
expect(field2.value).toBeUndefined()
316+
const field3 = attach(
317+
form.createField({
318+
name: 'field3',
319+
basePath: voidField.address,
320+
value: 1,
321+
})
322+
)
323+
expect(field1.value).toBe(1)
324+
expect(field2.value).toBe(1)
325+
field3.value = 2
326+
expect(field1.value).toBe(2)
327+
expect(field2.value).toBe(2)
328+
})

packages/core/src/models/Form.ts

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export class Form<ValueType extends object = any> {
122122
protected makeObservable() {
123123
define(this, {
124124
fields: observable.shallow,
125+
indexes: observable.shallow,
125126
initialized: observable.ref,
126127
validating: observable.ref,
127128
submitting: observable.ref,

0 commit comments

Comments
 (0)