mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-26 18:00:43 +01:00
feat(Form): add attach prop to opt-out of nested form attachement (#3939)
This commit is contained in:
@@ -39,7 +39,7 @@ async function onSubmit(event: FormSubmitEvent<Schema>) {
|
|||||||
<UCheckbox v-model="state.news" name="news" label="Register to our newsletter" @update:model-value="state.email = undefined" />
|
<UCheckbox v-model="state.news" name="news" label="Register to our newsletter" @update:model-value="state.email = undefined" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<UForm v-if="state.news" :state="state" :schema="nestedSchema">
|
<UForm v-if="state.news" :state="state" :schema="nestedSchema" attach>
|
||||||
<UFormField label="Email" name="email">
|
<UFormField label="Email" name="email">
|
||||||
<UInput v-model="state.email" placeholder="john@lennon.com" />
|
<UInput v-model="state.email" placeholder="john@lennon.com" />
|
||||||
</UFormField>
|
</UFormField>
|
||||||
|
|||||||
@@ -51,7 +51,14 @@ async function onSubmit(event: FormSubmitEvent<Schema>) {
|
|||||||
<UInput v-model="state.customer" placeholder="Wonka Industries" />
|
<UInput v-model="state.customer" placeholder="Wonka Industries" />
|
||||||
</UFormField>
|
</UFormField>
|
||||||
|
|
||||||
<UForm v-for="item, count in state.items" :key="count" :state="item" :schema="itemSchema" class="flex gap-2">
|
<UForm
|
||||||
|
v-for="item, count in state.items"
|
||||||
|
:key="count"
|
||||||
|
:state="item"
|
||||||
|
:schema="itemSchema"
|
||||||
|
attach
|
||||||
|
class="flex gap-2"
|
||||||
|
>
|
||||||
<UFormField :label="!count ? 'Description' : undefined" name="description">
|
<UFormField :label="!count ? 'Description' : undefined" name="description">
|
||||||
<UInput v-model="item.description" />
|
<UInput v-model="item.description" />
|
||||||
</UFormField>
|
</UFormField>
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ export interface FormProps<T extends object> {
|
|||||||
* @defaultValue `true`
|
* @defaultValue `true`
|
||||||
*/
|
*/
|
||||||
transform?: boolean
|
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.
|
* When `true`, all form elements will be disabled on `@submit` event.
|
||||||
* This will cause any focused input elements to lose their focus state.
|
* This will cause any focused input elements to lose their focus state.
|
||||||
@@ -70,6 +77,7 @@ const props = withDefaults(defineProps<FormProps<T>>(), {
|
|||||||
return ['input', 'blur', 'change'] as FormInputEvents[]
|
return ['input', 'blur', 'change'] as FormInputEvents[]
|
||||||
},
|
},
|
||||||
validateOnInputDelay: 300,
|
validateOnInputDelay: 300,
|
||||||
|
attach: true,
|
||||||
transform: true,
|
transform: true,
|
||||||
loadingAuto: 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 formId = props.id ?? useId() as string
|
||||||
|
|
||||||
const bus = useEventBus<FormEvent<T>>(`form-${formId}`)
|
const bus = useEventBus<FormEvent<T>>(`form-${formId}`)
|
||||||
const parentBus = inject(
|
const parentBus = props.attach && inject(
|
||||||
formBusInjectionKey,
|
formBusInjectionKey,
|
||||||
undefined
|
undefined
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user