Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

fix: model cleanup not working with nested schemas (fix #227) #228

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
2 changes: 1 addition & 1 deletion packages/formvuelate/src/utils/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const deleteFormModelProperty = (formModel, prop, path) => {
return
}

delete findNestedFormModelProp(path)[prop]
delete findNestedFormModelProp(formModel, path)[prop]
}

/**
Expand Down
47 changes: 47 additions & 0 deletions packages/formvuelate/tests/unit/SchemaForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,53 @@ describe('SchemaForm', () => {
})

describe('handling nested schemas', () => {
it('cleans up the model', async () => {
const schema = {
firstName: {
component: FormText,
label: 'First Name'
},
lastName: {
component: FormText,
label: 'Last Name'
},
properties: {
component: SchemaForm,
schema: {
favoriteThingAboutVue: {
component: FormSelect,
label: 'Favorite thing about Vue',
required: true,
condition: model => !!model.firstName,
options: ['Ease of use', 'Documentation', 'Community']
}
}
}
}

const formModel = ref({
firstName: 'Victor',
lastName: 'Lambert',
properties: {
favoriteThingAboutVue: 'Community'
}
})

const wrapper = mount(SchemaWrapperFactory(schema, null, formModel))

const copySchema = { ...schema }
delete copySchema.firstName
wrapper.setProps({
schema: copySchema
})
await wrapper.vm.$nextTick()

expect(formModel.value).toEqual({
lastName: 'Lambert',
properties: {}
})
})

it('injects the nestedSchemaModel prop as part of the path', () => {
const schema = {
firstName: {
Expand Down