Skip to content

Commit

Permalink
fix(core): fix void array items node need skip (#2683)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Dec 27, 2021
1 parent 80ef079 commit a67ab3a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
49 changes: 49 additions & 0 deletions packages/core/src/__tests__/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,52 @@ test('incomplete insertion of array elements', async () => {
expect(form.fields['array.2.aa']).toBeUndefined()
expect(form.fields['array.3.aa']).not.toBeUndefined()
})

test('void array items need skip data', () => {
const form = attach(createForm())
const array = attach(
form.createArrayField({
name: 'array',
})
)
const array2 = attach(
form.createArrayField({
name: 'array2',
})
)
attach(
form.createVoidField({
name: '0',
basePath: 'array',
})
)
attach(
form.createVoidField({
name: '0',
basePath: 'array2',
})
)
attach(
form.createVoidField({
name: 'space',
basePath: 'array.0',
})
)
const select = attach(
form.createField({
name: 'select',
basePath: 'array.0.space',
})
)
const select2 = attach(
form.createField({
name: 'select2',
basePath: 'array2.0',
})
)

select.value = 123
select2.value = 123
expect(array.value).toEqual([123])
expect(array2.value).toEqual([123])
})
4 changes: 3 additions & 1 deletion packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export const buildFieldPath = (field: GeneralField) => {
const currentAddress = segments.slice(0, index + 1)
const current = fields[currentAddress.join('.')]
if (prevArray) {
prevArray = false
if (!isVoidField(current)) {
prevArray = false
}
return path
}
if (index >= segments.length - 1) {
Expand Down

0 comments on commit a67ab3a

Please sign in to comment.