The date
field represents a date and time picker. It can be used for data values that are valid date strings.
The Date Field plugin is provided by the react-tinacms-date
package.
yarn add react-tinacms-date
import { DateFieldPlugin } from "react-tinacms-date"
cms.plugins.add(DateFieldPlugin)
Visit the plugins doc to learn how to reduce your initial bundle size by dynamically loading & registering the plugins.
This field plugin uses react-datetime
under the hood.
interface DateConfig extends FieldConfig, DatetimepickerProps {
component: 'date'
name: string
label?: string
description?: string
dateFormat?: boolean | string // Extra properties from react-datetime
timeFormat?: boolean | string // Moment date format
}
Option | Description |
---|---|
component | The name of the plugin component. Always 'date' . |
name | The path to some value in the data being edited. |
label | A human readable label for the field. Defaults to the name . (Optional) |
description | Description that expands on the purpose of the field or prompts a specific action. (Optional) |
dateFormat | Defines the format for the date. It accepts any Moment.js date format (not in localized format). If true the date will be displayed using the defaults for the current locale. See react-datetime docs for more details. (Optional) |
timeFormat | Defines the format for the time. It accepts any Moment.js time format (not in localized format). If true the time will be displayed using the defaults for the current locale. If false the timepicker is disabled and the component can be used as datepicker. See react-datetime docs for more details.(Optional) |
FieldConfig
This interfaces only shows the keys unique to the date field.
Visit the Field Config docs for a complete list of options.
DatetimepickerProps
Any extra properties added to the the
date
field definition will be passed along to thereact-datettime
component. Moment.js format is used. See the full list of options here.
Below is an example of how a date
field could be used to edit a created_at
date on a blog post.
const BlogPostForm = {
fields: [
{
label: 'Date',
name: 'created_at',
component: 'date',
dateFormat: 'MMMM DD YYYY',
timeFormat: false,
},
// ...
],
}