Skip to content
KeystoneJS LogoKeystoneJS

CalendarDay

Usage

JS
const { Text, Password, CalendarDay } = require('@keystonejs/fields');

keystone.createList('User', {
  fields: {
    email: { type: Text },
    password: { type: Password },
    lastOnline: {
      type: CalendarDay,
      format: 'Do MMMM YYYY',
      yearRangeFrom: 1901,
      yearRangeTo: 2018,
    },
  },
});

Config

OptionTypeDefaultDescription
formatStringYYYY-MM-DDDefines the format of string that the component will display
yearRangeFromIntegerThe current year - 100Defines the starting point of the year range, eg 1918
yearRangeToIntegerThe current yearDefines the ending point of the range in the yearSelect field , e.g 2018
isRequiredBooleanfalseDoes this field require a value?
isUniqueBooleanfalseAdds a unique index that allows only unique values to be stored

format

Defines the format of string that the component will display, such as Do MMMM YYYY. Values will be stored in the database in ISO8601 (YYYY-MM-DD) format.

yearRangeFrom

The CalendarDay component includes an input that allows the user to change the current year from a range of options. This prop allows the user to set the beginning of that range.

The default value for this field is 100 years before the current year.

yearRangeTo

The CalendarDay component includes an input that allows the user to change the current year from a range of options. This prop allows the user to set the end of that range.

The default value for this field is the current year.

GraphQL

CalendarDay fields use the String type in GraphQL. They produce values according to their configured format but always expect values in ISO8601 (YYYY-MM-DD) format.

Input fields

Field nameTypeDescription
${path}StringThe value to be stored, in ISO8601 (YYYY-MM-DD) format

Output fields

Field nameTypeDescription
${path}StringThe stored value in the configured format

Filters

All filter fields expect values in the ISO8601 (YYYY-MM-DD) format.

Field nameTypeDescription
${path}StringMatching the value provided
${path}_notStringNot matching the value provided
${path}_in[String]Matching any of the values provided
${path}_not_in[String]Matching none of the values provided
${path}_ltStringBefore than the value provided
${path}_lteStringBefore or equal to the value provided
${path}_gtStringMore recent than the value provided
${path}_gteStringMore recent or equal to the value provided

Storage

Mongoose adapter

In Mongoose the field is added using the String schema type.

The isRequired config option is enforced by KeystoneJS only.

Knex adapter

The Knex adapter uses the Knex date type:

The isRequired config option is enforced by KeystoneJS and, if equal to true, the column is set as not nullable.

On this page

  • Usage
  • Config
  • GraphQL
  • Input fields
  • Output fields
  • Filters
  • Storage
  • Mongoose adapter
  • Knex adapter
Edit on GitHub