Input
One native input. Use Field for labels and feedback, and Input Group for icons, text and actions inside a shared frame.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let labelledInput =
fveField {
fveLabel {
_for "exampleEmail"
"Email"
}
fveInput {
_id "exampleEmail"
_name "exampleEmail"
}
}This example also uses Field. See their Installation sections for any additional setup.
On this page
Installation
Copy this component and its required dependencies into the consumer-owned Components project.
dotnet fve add input --config src/Acme.Components/fve.jsonNo additional JavaScript import is required.
The CLI resolves dependencies and preserves consumer-authored files. See Installation for project initialization, Tailwind, the shared runtime, and building/loading your app entry.
Usage
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let labelledInput =
fveField {
fveLabel {
_for "exampleEmail"
"Email"
}
fveInput {
_id "exampleEmail"
_name "exampleEmail"
}
}required, type, pattern and length constraints use the browser's validity rules. :invalid matches any currently invalid value; :user-invalid delays native error styling until interaction/submission. These examples use Datastar to show inline errors after blur or invalid submission, then recheck on input so the border, aria-invalid, associated message and summary clear together as soon as the value is valid. Form reset clears this temporary feedback.
The nativeValidationAttributes helper is example-owned presentation, not an Input API or a second value model. Always validate submissions on the server. For server-only rules, recheck on the server and render _ariaInvalid with an associated Field error; a syntactically valid email does not prove that a server-only error is resolved. Read-only values remain submitted; disabled values do not.
Use Input Group for icons, prefixes, suffixes and actions inside the control frame.
Consistent control sizes
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let refreshIcon =
fveIcon { _name IconName.ArrowPath; _variant IconVariant.Micro }
let inputSizeExamples =
div {
_class "grid min-w-0 gap-6"
for size, name in [ Size.ExtraSmall, "Extra small"; Size.Small, "Compact"; Size.Medium, "Standard"; Size.Large, "Large"; Size.ExtraLarge, "Extra large" ] do
let key = name.ToLowerInvariant().Replace(" ", "-")
div {
_class (Size.className size + " flex flex-wrap items-end gap-3")
fveField {
fveLabel {
_for ("sizing-" + key)
Html.text (name + " search")
}
fveInput {
_id ("sizing-" + key)
_name ("sizing-" + key)
_type InputType.Search
}
}
fveField {
fveLabel {
_for ("sizing-type-" + key)
Html.text (name + " type")
}
fveSelect {
_id ("sizing-type-" + key)
_name ("sizing-type-" + key)
_value "all"
fveSelectContent {
for value, label, disabled in ([ ("all", "All types", false) ]) do
fveSelectItem {
_value value
_label label
_disabled disabled
}
}
}
}
div {
_class "flex flex-wrap items-center gap-3"
fveButton { Html.text (name + " action") }
fveButton {
_ariaLabel (name + " refresh")
span {
_ariaHidden true
_class "inline-flex shrink-0"
refreshIcon
}
}
}
}
div {
_class (Size.className Size.Small + " flex flex-wrap items-end gap-3")
fveField {
fveLabel {
_for "override-search"
"Larger search in a compact region"
}
fveInput {
_id "override-search"
_name "override-search"
_type InputType.Search
_size Size.Large
}
}
fveField {
fveLabel {
_for "override-type"
"Larger type"
}
fveSelect {
_id "override-type"
_name "override-type"
_value "all"
_size Size.Large
fveSelectContent {
for value, label, disabled in ([ ("all", "All types", false) ]) do
fveSelectItem {
_value value
_label label
_disabled disabled
}
}
}
}
div {
_class "flex flex-wrap items-center gap-3"
fveButton {
_size Size.Large
"Larger action"
}
fveButton {
_size Size.Large
_ariaLabel "Larger refresh"
span {
_ariaHidden true
_class "inline-flex shrink-0"
refreshIcon
}
}
}
}
}This example also uses Field, Select, Button, Icon. See their Installation sections for any additional setup.
With help text
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let inputWithHelp =
fveField {
fveLabel {
_for "helpEmail"
"Email"
}
fveInput {
_id "helpEmail"
_name "helpEmail"
_type InputType.Email
_placeholder "[email protected]"
_autocomplete "email"
_ariaDescribedby "helpEmail-description"
}
fveFieldDescription {
_id "helpEmail-description"
"We will use this address for updates."
}
}This example also uses Field. See their Installation sections for any additional setup.
Required
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let nativeValidationAttributes key initiallyShown (message: string) =
let checkedState = "$" + key + "_checked"
let error = "$" + key + "_error"
let refresh = error + " = el.validity.valid ? '' : " + System.Text.Json.JsonSerializer.Serialize(message)
let validate = checkedState + " = true; " + refresh
[ _dataSignals ($"{{{key}_checked: false, {key}_error: ''}}")
_dataOn ("blur", validate)
_dataOn ("input", $"if ({checkedState}) {{ {refresh} }}")
_dataOn ("invalid", validate)
_dataOn ("reset", ["window"], $"if (evt.target === el.form) queueMicrotask(() => {{ if (!evt.defaultPrevented) {{ {checkedState} = false; {error} = ''; }} }})")
_dataAttr ("aria-invalid", error + " ? 'true' : null")
if initiallyShown then _dataInit validate ]
let requiredInput =
fveField {
fveLabel { _for "requiredEmail"; "Email (required)" }
fveInput {
_id "requiredEmail"
_name "requiredEmail"
_type InputType.Email
_required true
_ariaDescribedby "required-email-help"
yield! nativeValidationAttributes "_required_email" false "Enter a valid email address."
_dataAttr ("aria-describedby", "$_required_email_error ? 'required-email-help required-email-error' : 'required-email-help'")
}
fveFieldDescription {
_id "required-email-help"
"Leave the field to check it. Correcting the email clears the error as you type."
}
fveFieldError {
_id "required-email-error"
_style "display:none"
_dataShow "$_required_email_error"
_dataText "$_required_email_error"
}
}This example also uses Field. See their Installation sections for any additional setup.
Optional
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let optionalInput =
fveField {
fveLabel {
_for "company"
"Company (optional)"
}
fveInput {
_id "company"
_name "company"
_autocomplete "organization"
}
}This example also uses Field. See their Installation sections for any additional setup.
Validation error
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let nativeValidationAttributes key initiallyShown (message: string) =
let checkedState = "$" + key + "_checked"
let error = "$" + key + "_error"
let refresh = error + " = el.validity.valid ? '' : " + System.Text.Json.JsonSerializer.Serialize(message)
let validate = checkedState + " = true; " + refresh
[ _dataSignals ($"{{{key}_checked: false, {key}_error: ''}}")
_dataOn ("blur", validate)
_dataOn ("input", $"if ({checkedState}) {{ {refresh} }}")
_dataOn ("invalid", validate)
_dataOn ("reset", ["window"], $"if (evt.target === el.form) queueMicrotask(() => {{ if (!evt.defaultPrevented) {{ {checkedState} = false; {error} = ''; }} }})")
_dataAttr ("aria-invalid", error + " ? 'true' : null")
if initiallyShown then _dataInit validate ]
let invalidInput =
fveField {
fveLabel { _for "invalidEmail"; "Email" }
fveInput {
_id "invalidEmail"
_name "invalidEmail"
_type InputType.Email
_value "not-an-email"
yield! nativeValidationAttributes "_invalid_email" true "Enter a valid email address."
_dataAttr ("aria-describedby", "$_invalid_email_error ? 'invalidEmail-validation' : null")
}
fveFieldError {
_id "invalidEmail-validation"
_style "display:none"
_dataShow "$_invalid_email_error"
_dataText "$_invalid_email_error"
}
}This example also uses Field. See their Installation sections for any additional setup.
Native search
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let searchInputExample =
fveField {
fveLabel {
_for "field-search"
"Search"
}
fveInput {
_name "query"
_id "field-search"
_type "search"
_placeholder "Search…"
_autocomplete "off"
}
}This example also uses Field. See their Installation sections for any additional setup.
Disabled
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let disabledInput =
fveField {
fveLabel {
_for "disabledEmail"
"Email"
}
fveInput {
_name "disabledEmail"
_value "[email protected]"
_disabled true
_id "disabledEmail"
}
}This example also uses Field. See their Installation sections for any additional setup.
Read-only
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let readOnlyInput =
fveField {
fveLabel { _for "readOnlyEmail"; "Read-only email" }
fveInput {
_id "readOnlyEmail"
_name "readOnlyEmail"
_value "[email protected]"
_readonly true
}
}This example also uses Field. See their Installation sections for any additional setup.
API reference
type InputType =
| Text
| Email
| Telephone
| Password
| Number
| Search
| Url
| Date
| Time
| DateTimeLocal
module InputDsl =
val fveInput : ComponentElementBuilder
module InputAttributes =
val Html._type.Static : value:InputType -> HtmlAttribute