Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix query sibling value is not work #2781

Merged
merged 3 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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