1
0
mirror of synced 2024-11-22 13:26:06 +03:00

fix: Fixed registry.getNested for array of fields

This commit is contained in:
1on 2020-11-02 11:59:26 +03:00
parent f52cd2e2e7
commit 96a991f46f
2 changed files with 35 additions and 1 deletions

View File

@ -72,7 +72,14 @@ export default class Registry {
const result = new Map() const result = new Map()
for (const i of this.registry.keys()) { for (const i of this.registry.keys()) {
if (i === key || i.includes(key + '.')) { const objectKey = key + '.'
const arrayKey = key + '['
if (
i === key ||
i.substring(0, objectKey.length) === objectKey ||
i.substring(0, arrayKey.length) === arrayKey
) {
result.set(i, this.registry.get(i)) result.set(i, this.registry.get(i))
} }
} }

View File

@ -68,6 +68,33 @@ describe('FormularioForm', () => {
expect(wrapper.findComponent(FormularioForm).vm.registry.keys()).toEqual(['sub2']) expect(wrapper.findComponent(FormularioForm).vm.registry.keys()).toEqual(['sub2'])
}) })
it('Getting nested fields from registry', async () => {
const wrapper = mount({
data: () => ({ active: true, nested: { groups: { value: 'value' } }, groups: [{ name: 'group1' }, { name: 'group2' }] }),
template: `
<FormularioForm>
<FormularioInput name="sub1" />
<FormularioInput name="sub2" />
<FormularioInput name="nested.groups.value" />
<FormularioInput name="groups">
<FormularioGrouping :name="'groups[' + index + ']'" v-for="(item, index) in groups" :key="index">
<FormularioInput name="name" />
</FormularioGrouping>
</FormularioInput>
</FormularioForm>
`
})
await flushPromises()
expect(Array.from(wrapper.findComponent(FormularioForm).vm.registry.getNested('sub1').keys())).toEqual(['sub1'])
expect(Array.from(wrapper.findComponent(FormularioForm).vm.registry.getNested('groups').keys()))
.toEqual(['groups', 'groups[0].name', 'groups[1].name'])
wrapper.setData({ active: true, groups: [{ name: 'group1' }] })
await flushPromises()
expect(Array.from(wrapper.findComponent(FormularioForm).vm.registry.getNested('groups').keys()))
.toEqual(['groups', 'groups[0].name'])
})
it('Can set a fields initial value', async () => { it('Can set a fields initial value', async () => {
const wrapper = mount(FormularioForm, { const wrapper = mount(FormularioForm, {
propsData: { formularioValue: { test: 'Has initial value' } }, propsData: { formularioValue: { test: 'Has initial value' } },