Skip to content

Commit

Permalink
hot-fix: update form parent searching
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenesius committed Oct 25, 2024
1 parent 3e6036b commit 962ed98
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/classes/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ export default class Form extends EventEmitter implements FormDependence {
const currentInstance = !!getCurrentInstance();
debug.msg(`new form %c${Form.restoreFullName(this)}%c`, debug.colorName, debug.colorDefault, this);

const parent = (currentInstance ? Form.getParentForm() : null) || params.parent
const parent = (params.parent === null || params.parent === false)
? null : ( params.parent || (currentInstance ? Form.getParentForm() : null));

if (parent) parent.subscribe(this);
if (params.provide !== false && currentInstance) provideVue(Form.PROVIDE_NAME, this); // Default providing current form for children.

Expand Down
16 changes: 16 additions & 0 deletions tests/integrations/components/AppSubscribe.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup lang="ts">
import Form from "./../../../src/classes/Form";
import FormWithSubscribeParent from "./FormWithSubscribeParent.vue";
const form = new Form();
</script>

<template>
<div>
<form-with-subscribe-parent/>
</div>
</template>

<style scoped>
</style>
17 changes: 17 additions & 0 deletions tests/integrations/components/AppWithoutSubscribe.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script setup lang="ts">
import Form from "./../../../src/classes/Form";
import FormWithoutSubscribeParent from "./FormWithoutSubscribeParent.vue";
const form = new Form();
</script>

<template>
<div>
<form-without-subscribe-parent/>
</div>
</template>

<style scoped>
</style>
17 changes: 17 additions & 0 deletions tests/integrations/components/FormWithSubscribeParent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script setup lang="ts">
import Form from "./../../../src/classes/Form";
const form = new Form({
name: "Test",
})
</script>

<template>
<div>

</div>
</template>

<style scoped>
</style>
18 changes: 18 additions & 0 deletions tests/integrations/components/FormWithoutSubscribeParent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script setup lang="ts">
import Form from "./../../../src/classes/Form";
const form = new Form({
name: "Test",
parent: false
})
</script>

<template>
<div>

</div>
</template>

<style scoped>
</style>
23 changes: 23 additions & 0 deletions tests/integrations/form-parent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {mount} from "@vue/test-utils";
import Form from "./../../src/classes/Form";
import AppSubscribe from "./components/AppSubscribe.vue";
import AppWithoutSubscribe from "./components/AppWithoutSubscribe.vue";

describe("Parent Form", () => {

test('with parent', () => {
const app = mount(AppSubscribe) as any;
const form = app.vm.form as Form;


expect(form.dependencies.length).toBe(1)
})

test('WithoutParent', () => {
const app = mount(AppWithoutSubscribe) as any;
const form = app.vm.form as Form;


expect(form.dependencies.length).toBe(0)
})
})

0 comments on commit 962ed98

Please sign in to comment.