On this page

Date field

The date field stores a timestamp in milliseconds to represent a date value.

Date field

Examples

Here's an example of using the date field in a block:

# blocks/Product.vue

<template>
  <div>
    <div v-if="releaseDate">
      <span>Release date:</span>
      <span>{{ new Date(releaseDate).toLocaleDateString() }}</span>
    </div>
    ...
  </div>
</template>

<script lang="ts" setup>
import { dateField } from '#pruvious'

defineProps({
  releaseDate: dateField({
    placeholder: 'Select a date',
    required: true,
  }),
})
</script>

Here is another example of how to use it in a collection definition:

# collections/products.ts

import { defineCollection } from '#pruvious'

export default defineCollection({
  name: 'products',
  mode: 'multi',
  fields: {
    releaseDate: {
      type: 'date',
      options: {
        placeholder: 'Select a date',
        required: true,
      },
    },
    // ...
  },
})

Options

You can specify the following options in the date field:

OptionDescription

clearable

A boolean indicating whether to display a clear button that removes the current value.

default

The default field value (null if not defined).

description

A brief descriptive text displayed in code comments and in a tooltip at the upper right corner of the field.

label

The field label displayed in the UI. By default, it is automatically generated based on the property name assigned to the field. For example, eventDate becomes Event date.

max

The latest possible date (as timestamp in milliseconds).

min

The earliest possible date (as timestamp in milliseconds).

name

A string that specifies the name for the input controls. If not specified, the name attribute will be automatically generated.

placeholder

Text that appears in the input element when it has no value set.

required

Specifies that the field input is mandatory during creation.

Last updated on January 6, 2024 at 17:01