Files
heroui-vue/apps/docs/demos/date-field-with-validation.vue
T
2026-10-23 23:56:18 +08:00

44 lines
1.1 KiB
Vue

<script setup lang="ts">
import {
DateField,
DateFieldGroup,
DateFieldInput,
DateFieldSegment,
Label,
Description,
FieldError,
} from "@heroui-vue/components";
import { shallowRef, computed } from "vue";
import {
today,
getLocalTimeZone,
type DateValue,
} from "@internationalized/date";
const value = shallowRef<DateValue | null>(null);
const todayDate = today(getLocalTimeZone());
const isInvalid = computed(
() => value.value !== null && value.value.compare(todayDate) < 0,
);
</script>
<template>
<div class="flex flex-col gap-4">
<DateField
v-model="value"
is-required
:is-invalid="isInvalid"
:min-value="todayDate"
class="w-[256px]"
name="date"
>
<Label>日期</Label>
<DateFieldGroup>
<DateFieldInput v-slot="{ segment }">
<DateFieldSegment :segment="segment" />
</DateFieldInput>
</DateFieldGroup>
<FieldError v-if="isInvalid">日期须为今天或将来</FieldError>
<Description v-else>输入日期 from today onwards</Description>
</DateField>
</div>
</template>