From 1a0d7a3103cf7591b019ef3ad685e2f3786ef6f2 Mon Sep 17 00:00:00 2001 From: Romain Hamel Date: Sun, 20 Apr 2025 17:29:36 +0200 Subject: [PATCH] feat(Form): add `attach` prop to opt-out of nested form attachement (#3939) --- .../content/examples/form/FormExampleNested.vue | 2 +- .../content/examples/form/FormExampleNestedList.vue | 9 ++++++++- src/runtime/components/Form.vue | 10 +++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/app/components/content/examples/form/FormExampleNested.vue b/docs/app/components/content/examples/form/FormExampleNested.vue index 78e0fea1..4d46e942 100644 --- a/docs/app/components/content/examples/form/FormExampleNested.vue +++ b/docs/app/components/content/examples/form/FormExampleNested.vue @@ -39,7 +39,7 @@ async function onSubmit(event: FormSubmitEvent) { - + diff --git a/docs/app/components/content/examples/form/FormExampleNestedList.vue b/docs/app/components/content/examples/form/FormExampleNestedList.vue index 195bdfc6..77f4ef3c 100644 --- a/docs/app/components/content/examples/form/FormExampleNestedList.vue +++ b/docs/app/components/content/examples/form/FormExampleNestedList.vue @@ -51,7 +51,14 @@ async function onSubmit(event: FormSubmitEvent) { - + diff --git a/src/runtime/components/Form.vue b/src/runtime/components/Form.vue index ffb6ada2..f12a33fa 100644 --- a/src/runtime/components/Form.vue +++ b/src/runtime/components/Form.vue @@ -36,6 +36,13 @@ export interface FormProps { * @defaultValue `true` */ transform?: boolean + + /** + * If true, this form will attach to its parent Form (if any) and validate at the same time. + * @defaultValue `true` + */ + attach?: boolean + /** * When `true`, all form elements will be disabled on `@submit` event. * This will cause any focused input elements to lose their focus state. @@ -70,6 +77,7 @@ const props = withDefaults(defineProps>(), { return ['input', 'blur', 'change'] as FormInputEvents[] }, validateOnInputDelay: 300, + attach: true, transform: true, loadingAuto: true }) @@ -84,7 +92,7 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.form || {}) const formId = props.id ?? useId() as string const bus = useEventBus>(`form-${formId}`) -const parentBus = inject( +const parentBus = props.attach && inject( formBusInjectionKey, undefined )