Display a date input widget that can be configured to accept a single date or a date range.

Method Signatures and Parameters

Jt.dateInput(String label)

label (String)

A short label explaining to the user what this date input is for. Markdown is supported, see Jt#markdown(String) for more details.

Chainable builder methods

value(java.time.LocalDate value)

The value of this widget when it first renders. Can be a specific date or null for no initial value.

minValue(java.time.LocalDate minValue)

The minimum selectable date. If null, defaults to ten years before the initial value.

maxValue(java.time.LocalDate maxValue)

The maximum selectable date. If null, defaults to ten years after the initial value.

help(String help)

A tooltip that gets displayed next to the text. If this is null (default), no tooltip is displayed.

onChange(function.Consumer<java.time.LocalDate> onChange)

An optional callback invoked when the date input's value changes. The value passed to the callback is the previous value of the component.

format(String format)

Controls how dates are displayed in the interface. Supported formats: YYYY/MM/DD, DD/MM/YYYY, MM/DD/YYYY. You may also use a period (.) or hyphen (-) as separators.

disabled(boolean disabled)

Disable the date input if set to true. When disabled, users cannot interact with the widget.

labelVisibility(JtComponent.LabelVisibility labelVisibility)

The visibility of the label. The default is VISIBLE. If this is HIDDEN, Jeamlit displays an empty spacer instead of the label, which can help keep the widget aligned with other widgets. If this is COLLAPSED, Jeamlit displays no label or spacer.

width(String width)

Controls the widget's width. Can be "stretch" to match parent container or a pixel value as string.

width(int widthPixels)

The width of the element in pixels. The element will have a fixed width. If the specified width is greater than the width of the parent container, the width of the element matches the width of the parent container.

key(String key)

A string to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. No two widgets may have the same key.

No description

use()

Put the widget in the app, in the MAIN container.

use(JtContainer container)

Put the widget in the app, in the provided container.

Returns after .use()

(LocalDate)

The current LocalDate value of the component.

Examples

Simple date input

 import tech.catheu.jeamlit.core.Jt;

 import java.time.LocalDate;
 import java.time.Period;

 public class DateInputApp {
     public static void main(String[] args) {
         LocalDate birthday = Jt.dateInput("Your birthday").use();

         if (birthday != null) {
             int age = Period.between(birthday, LocalDate.now()).getYears();
             Jt.text("You are " + age + " years old").use();
         }
     }
 }

forum

Still have questions?

Go to our discussions forum for helpful information and advice from Jeamlit experts.