shadcn-vue/apps/www/registry/new-york/example/AutoFormInputWithoutLabel.vue
2024-11-21 11:52:31 +08:00

45 lines
1.1 KiB
Vue

<script setup lang="ts">
import { AutoForm, AutoFormField } from '@/lib/registry/new-york/ui/auto-form'
import { Button } from '@/lib/registry/new-york/ui/button'
import { toast } from '@/lib/registry/new-york/ui/toast'
import { h } from 'vue'
import * as z from 'zod'
const schema = z.object({
username: z.string(),
})
function onSubmit(values: Record<string, any>) {
toast({
title: 'You submitted the following values:',
description: h('pre', { class: 'mt-2 w-[340px] rounded-md bg-slate-950 p-4' }, h('code', { class: 'text-white' }, JSON.stringify(values, null, 2))),
})
}
</script>
<template>
<AutoForm
class="w-2/3 space-y-6"
:schema="schema"
:field-config="{
username: {
hideLabel: true,
},
}"
@submit="onSubmit"
>
<template #username="slotProps">
<div class="flex items-center gap-3">
<div class="flex-1">
<AutoFormField v-bind="slotProps" />
</div>
<div>
<Button type="submit">
Update
</Button>
</div>
</div>
</template>
</AutoForm>
</template>