LogoLogo
WebsitePricingGitHubSign up
  • Getting started
    • Installation and usage
    • Form settings
    • Options
    • Frequently asked questions
    • Spam protection
    • React
  • Customization
    • Theming
    • Localization
  • Input types
    • Text input
    • Email input
    • URL input
    • Telephone input
    • Password input
    • Number input
    • Select box
    • Choice input
    • Picture choice
    • Rating input
    • Opinion scale / Net Promoter Score®
    • Datetime input
    • Date input
    • Time input
    • File input
  • Content
    • Slide
    • Start slide
    • End slide
    • Markdown
    • Data binding
    • CSS utility classes
  • Integrations
    • Google Sheets integration
Powered by GitBook

© 2025 Forms.md | All rights reserved

On this page
  • Basic usage
  • Required
  • Function overview
  • Arguments
  • Parameters
  • Shared parameters
  • Date input specific parameters
  • Examples
  • Date input with validation
  • Date input with default value
  • Styled date input with custom attributes
  • Conditional display

Was this helpful?

  1. Input types

Date input

Create date inputs in your forms.

PreviousDatetime inputNextTime input

Last updated 4 months ago

Was this helpful?

Use the dateInput() function to create date inputs in your forms. It uses the HTML <input type="date"> element which provides built-in date selection and validation.


Basic usage

import { Composer } from "formsmd";

const composer = new Composer({
  id: "my-form"
});

composer.dateInput("birthdate", {
  question: "What is your birth date?"
});

Generates the following Markdown-like syntax:

#! id = my-form

birthdate = DateInput(
  | question = What is your birth date?
)

Required

Add the required parameter to make the field mandatory:

composer.dateInput("birthdate", {
  question: "What is your birth date?",
  required: true
});

Generates the following Markdown-like syntax:

birthdate* = DateInput(
  | question = What is your birth date?
)

Function overview

The following is the overview of the function:

dateInput(name: string, params: object)

Arguments

Name
Type
Description

name

string

A unique name for your form field that you'll use to identify the user's response.*

params

object


Parameters

Shared parameters

These parameters are common to all form fields:

Name
Type
Description

question (required)

string

The main question or label of the form field.

required

true (boolean)

When set, the field becomes required.

description

string

Any extra information that the user may need to fill out the form. Appears right below the question.

fieldSize

"sm"

When set to "sm", the font sizes of the question, description, and answer are made smaller.

labelStyle

"classic"

When set to "classic", the question and description of the form field are made smaller.

subfield

true (boolean)

When set, the question and description of the form field are made smaller. Functionally the same as setting labelStyle to "classic".

disabled

true (boolean)

When set, the input is disabled.

autofocus

true (boolean)

When set, the input will be automatically focused when the parent slide becomes active, or immediately after page load.

id

string

The id attribute of the form field container.

classNames

string[]

attrs

Array<{ name: string, value: string }>

Other HTML attributes of the form field. Each attribute has a name and value property.

displayCondition

{ dependencies: string[], condition: string }

Date input specific parameters

Name
Type
Description

placeholder

string

Sets the placeholder attribute of the input.

min

string

Sets the minimum allowed date value ("YYYY-MM-DD").

max

string

Sets the maximum allowed date value ("YYYY-MM-DD").

step

string

Sets the stepping interval.

value

string

Pre-selected date value ("YYYY-MM-DD").


Examples

Date input with validation

composer.dateInput("appointmentDate", {
  question: "When would you like to schedule your appointment?",
  description: "Please select a date within the next 30 days",
  min: "2024-01-12",
  max: "2024-02-12",
  required: true
});

Generates the following Markdown-like syntax:

appointmentDate* = DateInput(
  | question = When would you like to schedule your appointment?
  | description = Please select a date within the next 30 days
  | min = 2024-01-12
  | max = 2024-02-12
)

Date input with default value

composer.dateInput("startDate", {
  question: "Start date",
  description: "When would you like to begin?",
  value: "2024-01-12"
});

Generates the following Markdown-like syntax:

startDate = DateInput(
  | question = Start date
  | description = When would you like to begin?
  | value = 2024-01-12
)

Styled date input with custom attributes

Add CSS classes and other HTML attributes using the classNames and attrs parameters. Please note, these class names and attributes are added to the <div> or <fieldset> container that contains the actual input field(s).

composer.dateInput("eventDate", {
  question: "Event date",
  classNames: ["col-6", "xs:col-6"],
  attrs: [
    { name: "style", value: "font-size: 18px;" }
  ]
});

Generates the following Markdown-like syntax:

[.col-6 .xs:col-6 style="font-size: 18px;"]
eventDate = DateInput(
  | question = Event date
)

Conditional display

Conditionally show or hide a date input field using the displayCondition parameter. It works as follows:

  • dependencies lists the fields to watch.

For instance, in the example below, the return date input will only show up if the user indicates they want to book a round trip.

composer.choiceInput("tripType", {
  question: "What type of trip would you like to book?",
  required: true,
  choices: ["One-way", "Round trip"]
})

composer.dateInput("returnDate", {
  question: "Return date",
  displayCondition: {
    dependencies: ["tripType"],
    condition: "tripType == 'Round trip'"
  }
});

Generates the following Markdown-like syntax:

tripType* = ChoiceInput(
  | question = What type of trip would you like to book?
  | choices = One-way, Round trip
)

::: [{$ tripType $}]
{% if tripType == "Round trip" %}
returnDate = DateInput(
  | question = Return date
)
{% endif %}
:::

An object containing all the configuration parameters for your date input field (see the below for the full list of options).

*Avoid values for the name argument which may be the names of HTML attributes, such as "name", "role", "id", etc. This is because by default, the form's template string is first sanitized using , and these values may be removed to prevent DOM clobbering.

The CSS class names of the form field. .

Controls when the field is shown. The dependencies lists the fields to watch, and condition is the expression that must be true to show the field. The condition must be a valid expression. .

Please .

condition is the expression that must be true to show the field. This must be a valid expression.

DOMPurify
see the available CSS utility classes
Nunjucks
parameters section
See the available CSS utility classes
Nunjucks
See example
Date input