Skip to content

Commit 962ed98

Browse files
committed
hot-fix: update form parent searching
1 parent 3e6036b commit 962ed98

File tree

6 files changed

+94
-1
lines changed

6 files changed

+94
-1
lines changed

src/classes/Form.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ export default class Form extends EventEmitter implements FormDependence {
162162
const currentInstance = !!getCurrentInstance();
163163
debug.msg(`new form %c${Form.restoreFullName(this)}%c`, debug.colorName, debug.colorDefault, this);
164164

165-
const parent = (currentInstance ? Form.getParentForm() : null) || params.parent
165+
const parent = (params.parent === null || params.parent === false)
166+
? null : ( params.parent || (currentInstance ? Form.getParentForm() : null));
167+
166168
if (parent) parent.subscribe(this);
167169
if (params.provide !== false && currentInstance) provideVue(Form.PROVIDE_NAME, this); // Default providing current form for children.
168170

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script setup lang="ts">
2+
import Form from "./../../../src/classes/Form";
3+
import FormWithSubscribeParent from "./FormWithSubscribeParent.vue";
4+
5+
const form = new Form();
6+
</script>
7+
8+
<template>
9+
<div>
10+
<form-with-subscribe-parent/>
11+
</div>
12+
</template>
13+
14+
<style scoped>
15+
16+
</style>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script setup lang="ts">
2+
import Form from "./../../../src/classes/Form";
3+
import FormWithoutSubscribeParent from "./FormWithoutSubscribeParent.vue";
4+
5+
6+
const form = new Form();
7+
</script>
8+
9+
<template>
10+
<div>
11+
<form-without-subscribe-parent/>
12+
</div>
13+
</template>
14+
15+
<style scoped>
16+
17+
</style>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script setup lang="ts">
2+
import Form from "./../../../src/classes/Form";
3+
4+
const form = new Form({
5+
name: "Test",
6+
})
7+
</script>
8+
9+
<template>
10+
<div>
11+
12+
</div>
13+
</template>
14+
15+
<style scoped>
16+
17+
</style>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script setup lang="ts">
2+
import Form from "./../../../src/classes/Form";
3+
4+
const form = new Form({
5+
name: "Test",
6+
parent: false
7+
})
8+
</script>
9+
10+
<template>
11+
<div>
12+
13+
</div>
14+
</template>
15+
16+
<style scoped>
17+
18+
</style>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {mount} from "@vue/test-utils";
2+
import Form from "./../../src/classes/Form";
3+
import AppSubscribe from "./components/AppSubscribe.vue";
4+
import AppWithoutSubscribe from "./components/AppWithoutSubscribe.vue";
5+
6+
describe("Parent Form", () => {
7+
8+
test('with parent', () => {
9+
const app = mount(AppSubscribe) as any;
10+
const form = app.vm.form as Form;
11+
12+
13+
expect(form.dependencies.length).toBe(1)
14+
})
15+
16+
test('WithoutParent', () => {
17+
const app = mount(AppWithoutSubscribe) as any;
18+
const form = app.vm.form as Form;
19+
20+
21+
expect(form.dependencies.length).toBe(0)
22+
})
23+
})

0 commit comments

Comments
 (0)