Skip to content

Commit

Permalink
fix(core): fix void field child field reactions not work in some cases (
Browse files Browse the repository at this point in the history
#3415)

* feat: set Form indexes observable

* feat: add test cases
  • Loading branch information
coolbob1998 committed Sep 30, 2022
1 parent b3d3eb7 commit f05cb6b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/core/src/__tests__/void.spec.ts
Expand Up @@ -285,3 +285,44 @@ test('fault tolerance', () => {
expect(field.display).toEqual('visible')
expect(field.pattern).toEqual('editable')
})

test('child field reactions', () => {
const form = attach(createForm())
const voidField = attach(form.createVoidField({ name: 'void' }))
const field1 = attach(
form.createField({
name: 'field1',
basePath: voidField.address,
reactions: [
(field) => {
field.value = field.query('field3').getIn('value')
},
],
})
)
const field2 = attach(
form.createField({
name: 'field2',
basePath: voidField.address,
reactions: [
(field) => {
field.value = field.query('.field3').getIn('value')
},
],
})
)
expect(field1.value).toBeUndefined()
expect(field2.value).toBeUndefined()
const field3 = attach(
form.createField({
name: 'field3',
basePath: voidField.address,
value: 1,
})
)
expect(field1.value).toBe(1)
expect(field2.value).toBe(1)
field3.value = 2
expect(field1.value).toBe(2)
expect(field2.value).toBe(2)
})
1 change: 1 addition & 0 deletions packages/core/src/models/Form.ts
Expand Up @@ -122,6 +122,7 @@ export class Form<ValueType extends object = any> {
protected makeObservable() {
define(this, {
fields: observable.shallow,
indexes: observable.shallow,
initialized: observable.ref,
validating: observable.ref,
submitting: observable.ref,
Expand Down

0 comments on commit f05cb6b

Please sign in to comment.