> Note: Dash.NET is currently considered experimental. If your organization is interested in sponsoring Dash.NET, please get in touch.

# DCC.Input.input

The `DCC.Input.input` component creates input fields for text, numbers, passwords, and more, allowing dynamic user input.

## Examples

Find a few usage examples below.

### Supported Input Types

    open Dash.NET

    let out_all_types = "out-all-types"
    let outputTarget = out_all_types @. Children

    let ALLOWED_TYPES = [
        InputType.Text
        InputType.Number
        InputType.Password
        InputType.Email
        InputType.Search
        InputType.Tel
        InputType.Url
        InputType.Range
        InputType.Hidden
    ]

    let layout =
        Html.div [
            Attr.children [
                for t in ALLOWED_TYPES ->
                    Input.input (sprintf "input_%s" (InputType.toString t)) [
                        Input.Attr.inputType t
                        Input.Attr.placeholder (sprintf "input type %s" (InputType.toString t))
                        Input.Attr.value ""
                    ]
                yield Html.div [ Attr.id out_all_types ]
            ]
        ]

    let callback =
        Callback.singleOut (
            [ for t in ALLOWED_TYPES -> ((sprintf "input_%s" (InputType.toString t)) @. Value) ],
            outputTarget,
            (fun textInput
                 numberInput
                 passwordInput
                 emailInput
                 searchInput
                 telInput
                 urlInput
                 rangeInput
                 hiddenInput ->
                outputTarget =>
                    System.String.Join(
                        " | ",
                        [ textInput
                          numberInput
                          passwordInput
                          emailInput
                          searchInput
                          telInput
                          urlInput
                          rangeInput
                          hiddenInput ]
                    )
            ),
            PreventInitialCall = true
        )

    [<EntryPoint>]
    let main args =
        DashApp.initDefault()
        |> DashApp.withLayout layout
        |> DashApp.addCallback callback
        |> DashApp.run args

Sign up for Dash Club → Two free cheat sheets plus updates from Chris Parmer and Adam Schroeder delivered to your inbox every two months. Includes tips and tricks, community apps, and deep dives into the Dash architecture. Join now.

### Debounce Delays the Input Processing

    open Dash.NET

    let input1 = "input1"
    let input2 = "input2"
    let output = "output"
    let outputTarget = output @. Children

    let externalStylesheets = [ "https://codepen.io/chriddyp/pen/bWLwgP.css" ]

    let layout =
        Html.div [
            Attr.children [
                Html.i [
                    Attr.children [
                        Html.text """Try typing in input 1 & 2, and observe how debounce
                        is impacting the callbacks. Press Enter and/or Tab key in
                        Input 2 to cancel the delay"""
                    ]
                ]
                Html.br []
                Input.input input1 [
                    Input.Attr.inputType InputType.Text
                    Input.Attr.placeholder ""
                    Input.Attr.value ""
                    Input.Attr.style [ StyleProperty ("marginRight", "10px") ]
                ]
                Input.input input2 [
                    Input.Attr.inputType InputType.Text
                    Input.Attr.placeholder ""
                    Input.Attr.value ""
                    Input.Attr.debounce true
                ]
                Html.div [ Attr.id output ]
            ]
        ]

    let callback =
        Callback.singleOut (
            [ input1 @. Value
              input2 @. Value ],
            outputTarget,
            (fun input1 input2 ->
                outputTarget => sprintf "Input 1 \"%s\" and Input 2 \"%s\"" input1 input2),
            PreventInitialCall = true
        )

    [<EntryPoint>]
    let main args =
        DashApp.initDefault()
        |> DashApp.appendCSSLinks externalStylesheets
        |> DashApp.withLayout layout
        |> DashApp.addCallback callback
        |> DashApp.run args

### Number Input

Number type is now close to native HTML5 `input` behavior across browsers. We also apply a strict number casting in callbacks: valid number converts into corresponding number types, and invalid number converts into null. E.g.

    Input.input "range" [
        Input.Attr.inputType InputType.Number
        Input.Attr.value null
        Input.Attr.min 2; Input.Attr.max 10; Input.Attr.step 1
    ]

type 3 and 11 will return respectively integer three and `null` in F# callbacks.

> Important Notice re Integer vs Float: There is a limitation when converting numbers like 1.0 or 0.0: the corresponding number type in callbacks is Integer instead of Float. Add extra guard casting like `float` within callbacks if needed.

    open System
    open Dash.NET

    let dfalse = "dfalse"
    let dtrue = "dtrue"
    let input_range = "input_range"
    let number_out = "number-out"
    let outputTarget = number_out @. Children

    let layout =
        Html.div [
            Attr.children [
                Input.input dfalse [
                    Input.Attr.inputType InputType.Number
                    Input.Attr.placeholder "Debounce False"
                    Input.Attr.value null
                ]
                Input.input dtrue [
                    Input.Attr.inputType InputType.Number
                    Input.Attr.placeholder "Debounce True"
                    Input.Attr.value null
                    Input.Attr.debounce true
                ]
                Input.input input_range [
                    Input.Attr.inputType InputType.Number
                    Input.Attr.placeholder "input with range"
                    Input.Attr.value null
                    Input.Attr.min 10; Input.Attr.max 100; Input.Attr.step 3
                ]
                Html.hr []
                Html.div [ Attr.id number_out ]
            ]
        ]

    let callback =
        Callback.singleOut (
            [ dfalse @. Value
              dtrue @. Value
              input_range @. Value ],
            outputTarget,
            (fun (fval: Nullable<int>) (tval: Nullable<int>) (rangeval: Nullable<int>) ->
                outputTarget => sprintf "dfalse: %A, dtrue: %A range: %A" fval tval rangeval),
            PreventInitialCall = true
        )

    [<EntryPoint>]
    let main args =
        DashApp.initDefault()
        |> DashApp.withLayout layout
        |> DashApp.addCallback callback
        |> DashApp.run args

## Input Properties

> Our recommended IDE for writing Dash apps is Dash Enterprise's Data Science Workspaces, which has typeahead support for Dash Component Properties. Find out if your company is using Dash Enterprise.

`value` (string | number; optional): The value of the input.

`type` (a value equal to: 'text', 'number', 'password', 'email', 'range', 'search', 'tel', 'url' or 'hidden'; default `'text'`): The type of control to render.

`debounce` (bool | number; default `false`): If true, changes to input will be sent back to the Dash server only on enter or when losing focus. If it's false, it will send the value back on every change. If a number, it will not send anything back to the Dash server until the user has stopped typing for that number of seconds.

`placeholder` (string | number; optional): A hint to the user of what can be entered in the control . The placeholder text must not contain carriage returns or line-feeds. Note: Do not use the placeholder attribute instead of a <label> element, their purposes are different. The <label> attribute describes the role of the form element (i.e. it indicates what kind of information is expected), and the placeholder attribute is a hint about the format that the content should take. There are cases in which the placeholder attribute is never displayed to the user, so the form must be understandable without it.

`n_submit` (number; default `0`): Number of times the `Enter` key was pressed while the input had focus.

`n_submit_timestamp` (number; default `-1`): Last time that `Enter` was pressed.

`inputMode` (a value equal to: 'verbatim', 'latin', 'latin-name', 'latin-prose', 'full-width-latin', 'kana', 'katakana', 'numeric', 'tel', 'email' or 'url'; optional): Provides a hint to the browser as to the type of data that might be entered by the user while editing the element or its contents.

`autoComplete` (string; optional): This attribute indicates whether the value of the control can be automatically completed by the browser.

`readOnly` (bool | a value equal to: 'readOnly', 'readonly' or 'READONLY'; optional): This attribute indicates that the user cannot modify the value of the control. The value of the attribute is irrelevant. If you need read-write access to the input value, do not add the "readonly" attribute. It is ignored if the value of the type attribute is hidden, range, color, checkbox, radio, file, or a button type (such as button or submit). readOnly is an HTML boolean attribute - it is enabled by a boolean or 'readOnly'. Alternative capitalizations `readonly` & `READONLY` are also acccepted.

`required` (a value equal to: 'required' or 'REQUIRED' | bool; optional): This attribute specifies that the user must fill in a value before submitting a form. It cannot be used when the type attribute is hidden, image, or a button type (submit, reset, or button). The :optional and :required CSS pseudo-classes will be applied to the field as appropriate. required is an HTML boolean attribute - it is enabled by a boolean or 'required'. Alternative capitalizations `REQUIRED` are also acccepted.

`autoFocus` (a value equal to: 'autoFocus', 'autofocus' or 'AUTOFOCUS' | bool; optional): The element should be automatically focused after the page loaded. autoFocus is an HTML boolean attribute - it is enabled by a boolean or 'autoFocus'. Alternative capitalizations `autofocus` & `AUTOFOCUS` are also acccepted.

`disabled` (a value equal to: 'disabled' or 'DISABLED' | bool; optional): If true, the input is disabled and can't be clicked on. disabled is an HTML boolean attribute - it is enabled by a boolean or 'disabled'. Alternative capitalizations `DISABLED`.

`list` (string; optional): Identifies a list of pre-defined options to suggest to the user. The value must be the id of a <datalist> element in the same document. The browser displays only options that are valid values for this input element. This attribute is ignored when the type attribute's value is hidden, checkbox, radio, file, or a button type.

`multiple` (bool; optional): This Boolean attribute indicates whether the user can enter more than one value. This attribute applies when the type attribute is set to email or file, otherwise it is ignored.

`spellCheck` (a value equal to: 'true' or 'false' | bool; optional): Setting the value of this attribute to true indicates that the element needs to have its spelling and grammar checked. The value default indicates that the element is to act according to a default behavior, possibly based on the parent element's own spellcheck value. The value false indicates that the element should not be checked.

`name` (string; optional): The name of the control, which is submitted with the form data.

`min` (string | number; optional): The minimum (numeric or date-time) value for this item, which must not be greater than its maximum (max attribute) value.

`max` (string | number; optional): The maximum (numeric or date-time) value for this item, which must not be less than its minimum (min attribute) value.

`step` (string | number; default `'any'`): Works with the min and max attributes to limit the increments at which a numeric or date-time value can be set. It can be the string any or a positive floating point number. If this attribute is not set to any, the control accepts only values at multiples of the step value greater than the minimum.

`minLength` (string | number; optional): If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the minimum number of characters (in Unicode code points) that the user can enter. For other control types, it is ignored.

`maxLength` (string | number; optional): If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the maximum number of characters (in UTF-16 code units) that the user can enter. For other control types, it is ignored. It can exceed the value of the size attribute. If it is not specified, the user can enter an unlimited number of characters. Specifying a negative number results in the default behavior (i.e. the user can enter an unlimited number of characters). The constraint is evaluated only when the value of the attribute has been changed.

`pattern` (string; optional): A regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url, email, or password, otherwise it is ignored. The regular expression language is the same as JavaScript RegExp algorithm, with the 'u' parameter that makes it treat the pattern as a sequence of unicode code points. The pattern is not surrounded by forward slashes.

`selectionStart` (string; optional): The offset into the element's text content of the first selected character. If there's no selection, this value indicates the offset to the character following the current text input cursor position (that is, the position the next character typed would occupy).

`selectionEnd` (string; optional): The offset into the element's text content of the last selected character. If there's no selection, this value indicates the offset to the character following the current text input cursor position (that is, the position the next character typed would occupy).

`selectionDirection` (string; optional): The direction in which selection occurred. This is "forward" if the selection was made from left-to-right in an LTR locale or right-to-left in an RTL locale, or "backward" if the selection was made in the opposite direction. On platforms on which it's possible this value isn't known, the value can be "none"; for example, on macOS, the default direction is "none", then as the user begins to modify the selection using the keyboard, this will change to reflect the direction in which the selection is expanding.

`n_blur` (number; default `0`): Number of times the input lost focus.

`n_blur_timestamp` (number; default `-1`): Last time the input lost focus.

`size` (string; optional): The initial size of the control. This value is in pixels unless the value of the type attribute is text or password, in which case it is an integer number of characters. Starting in, this attribute applies only when the type attribute is set to text, search, tel, url, email, or password, otherwise it is ignored. In addition, the size must be greater than zero. If you do not specify a size, a default value of 20 is used.' simply states "the user agent should ensure that at least that many characters are visible", but different characters can have different widths in certain fonts. In some browsers, a certain string with x characters will not be entirely visible even if size is defined to at least x.

`style` (record; optional): The input's inline styles.

`className` (string; optional): The class of the input element.

`id` (string; optional): The ID of this component, used to identify dash components in callbacks. The ID needs to be unique across all of the components in an app.

`loading_state` (record; optional): Object that holds the loading state object coming from dash-renderer.

`loading_state` is a record with keys:

- `component_name` (string; optional): Holds the name of the component that is loading.

- `is_loading` (bool; optional): Determines if the component is loading or not.

- `prop_name` (string; optional): Holds which property is loading.

`persistence` (bool | string | number; optional): Used to allow user interactions in this component to be persisted when the component - or the page - is refreshed. If `persisted` is truthy and hasn't changed from its previous value, a `value` that the user has changed while using the app will keep that change, as long as the new `value` also matches what was given originally. Used in conjunction with `persistence_type`.

`persisted_props` (list of values equal to: 'value'; default `['value']`): Properties whose user interactions will persist after refreshing the component or the page. Since only `value` is allowed this prop can normally be ignored.

`persistence_type` (a value equal to: 'local', 'session' or 'memory'; default `'local'`): Where persisted user changes will be stored: memory: only kept in memory, reset on page refresh. local: window.localStorage, data is kept after the browser quit. session: window.sessionStorage, data is cleared once the browser quit.