Skip to content

Commit

Permalink
fix(core): fix query sibling value is not work (#2781)
Browse files Browse the repository at this point in the history
* fix(core): fix query sibling value is not work

* chore: improve tests

* fix(element): add checkbox default export
  • Loading branch information
janryWang authored Jan 20, 2022
1 parent 25c4897 commit c5dfb53
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
39 changes: 39 additions & 0 deletions packages/core/src/__tests__/field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1935,3 +1935,42 @@ test('field visible default value should work', () => {
select.value = 'visible'
expect(form.values.obj.input1).toBe('123')
})

test('query value with sibling path syntax', () => {
const form = attach(createForm())
const fn = jest.fn()
attach(
form.createVoidField({
name: 'void',
})
)
attach(
form.createObjectField({
name: 'obj',
basePath: 'void',
})
)
attach(
form.createField({
name: 'input',
basePath: 'void.obj',
reactions: [
(field) => {
fn(
field.query('.textarea').value(),
field.query('.textarea').initialValue()
)
},
],
})
)
const textarea = attach(
form.createField({
name: 'textarea',
basePath: 'void.obj',
initialValue: 'aaa',
})
)
textarea.value = '123'
expect(fn).toBeCalledWith('123', 'aaa')
})
4 changes: 2 additions & 2 deletions packages/core/src/models/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export class Query {
}

value() {
return this.form.getValuesIn(this.pattern)
return this.get('value')
}

initialValue() {
return this.form.getInitialValuesIn(this.pattern)
return this.get('initialValue')
}
}
2 changes: 2 additions & 0 deletions packages/element/src/checkbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ const CheckboxGroup = connect(
export const Checkbox = composeExport(connect(CheckboxOption), {
Group: CheckboxGroup,
})

export default Checkbox

0 comments on commit c5dfb53

Please sign in to comment.