Page tree
Skip to end of metadata
Go to start of metadata

DateFieldDefinition  renders a calendar that allows the user to select a date and optionally a time.

Class: info.magnolia.ui.form.field.definition.DateFieldDefinition

Date field properties

Simple date field

form:
  tabs:
    - name: tabText
      label: Text
      fields:
        - name: date
          class: info.magnolia.ui.form.field.definition.DateFieldDefinition
          time: false
          type: Date
          label: Date
          defaultValue: now

Node name

Value

 form


 tabs


 tabText


 fields


 date


 class

info.magnolia.ui.form.field.definition.DateFieldDefinition

 time

false

 type

Date

 label

Date

 defaultValue

now

You can use common field properties  and the following properties in a date field definition:

Properties:

<field name>

time

optional, default is false

Enables time selection. Renders dropdown boxes at the bottom of the calendar.

type

required

Set the type property to Date to ensure that the value is saved as a Calendar object and not a String. The addition of this property is essential.

dateFormat

optional, default is yyyy-MM-dd

Format in which the date is displayed to users. See SimpleDateFormat class for allowed patterns.

Examples:

dateFormat: yyyy-MM-dd           # 2017-10-31
dateFormat: yyyy-MMMM-dd         # 2017-October-31
dateFormat: EEE, MMM d, yyyy     # Tue, Oct 31, 2017

timeFormat

optional, default is HH:mm

Format in which time is displayed to users. See SimpleDateFormat class for allowed patterns.

Examples:

timeFormat: HH:mm     # 15:09
timeFormat: h:mm a    # 3:09 PM

defaultValue

optional, default is now

Set the default value to a specific date such as "2017-10-31" or use the keyword now which defaults to the current date and time. Current time means time at the host server. Magnolia stores dates and times using server time. The stored time is converted and displayed to users in their preferred time zone.

The default value only applies to new content items, not to existing content items that have been created previously.

(warning) Enclose the default value in quotes when using YAML:

defaultValue: "2017-10-31"
defaultValue: "2017-10-31 15:09"

If you define the dateFormat or timeFormat properties then provide the defaultValue using those same formats:

dateFormat: MM/dd/yyyy
timeFormat: h:mm a
defaultValue: "10/31/2017 3:09 PM"
  • No labels

6 Comments

  1. Christoph Meier –  Have you guys thought about putting in a simple property to allow the date field's value to be pre-filled with the current date/time when they arrive to the dialog?

    1. Hello Emilio

      I'm not sure whether we already thought about that or whether there is already a ticket for this.

      However, feel free to suggest it - use the Suggestion Box

    2. Emilio

      F.Y.I.
      This change has been implemented (smile) see  MGNLUI-4086 - Getting issue details... STATUS . It will be released with Magnolia 5.5.5 in these days.

      1. That's awesome!!! Thanks so much.

        1. Emilio, we were curious about your use case for prefilling the current date. Can you share an example where you plan to use it?

          We can think many use cases for setting a future date, such as entering a bunch of events to occur on a future date. However, current date is already automatically recorded in properties such as mgnl:created and mgnl:lastModified.

          1. Sure! I use this dialog in a blog post page where content editors are writing new posts often. It would be convenient if this dialog had today's date pre-filled when the content writer was writing a new post, as this is a standard in Blogging platforms.