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 empty string or number can not rewrite default value #2906

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 @@ -2002,3 +2002,42 @@ test('relative query with void field', () => {

expect(bb.query('.aa').take()).toBe(aa)
})

test('empty string or number value need rewrite default value', () => {
const form = attach(
createForm<any>({
values: {
aa: '',
bb: 0,
},
})
)
attach(
form.createField({
name: 'aa',
initialValue: 'test',
})
)
attach(
form.createField({
name: 'bb',
initialValue: 123,
})
)
attach(
form.createField({
name: 'cc',
initialValue: 'test',
})
)
attach(
form.createField({
name: 'dd',
initialValue: 123,
})
)
expect(form.values.aa).toEqual('')
expect(form.values.bb).toEqual(0)
expect(form.values.cc).toEqual('test')
expect(form.values.dd).toEqual(123)
})
5 changes: 5 additions & 0 deletions packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,11 @@ export const allowAssignDefaultValue = (target: any, source: any) => {
return false
}

if (typeof target === typeof source) {
if (target === '') return false
if (target === 0) return false
}

if (isEmptyTarget) {
if (isEmptySource) {
return false
Expand Down