Textarea
Collect multiline text with a native textarea. Compose labels and feedback with Field.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let labelledTextarea =
fveField {
fveLabel {
_for "message"
"Message"
}
fveTextarea {
_id "message"
_name "message"
}
}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 textarea --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 labelledTextarea =
fveField {
fveLabel {
_for "message"
"Message"
}
fveTextarea {
_id "message"
_name "message"
}
}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.
Visually hidden label
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let composerTextarea =
fveField {
fveLabel {
_for "reply"
_class "sr-only"
"Message"
}
fveTextarea {
_id "reply"
_name "reply"
_rows 1
_required true
_placeholder "Write a message…"
}
}This example also uses Field. See their Installation sections for any additional setup.
With instructions
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let editableInstructions =
fveField {
fveLabel {
_for "instructions-editable"
"Instructions"
}
fveTextarea {
_id "instructions-editable"
_name "instructions"
_value "Include the reference number when you reply."
_maxlength 400
_ariaDescribedby (String.concat " " [ ("instructions-editable") + "-description" ])
}
fveFieldDescription {
_id ("instructions-editable" + "-description")
"Maximum 400 characters."
}
}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 invalidTextarea =
fveField {
fveLabel { _for "invalidMessage"; "Message" }
fveTextarea {
_id "invalidMessage"
_name "invalidMessage"
_required true
yield! nativeValidationAttributes "_invalid_message" true "Enter a message before continuing."
_dataAttr ("aria-describedby", "$_invalid_message_error ? 'invalidMessage-validation' : null")
}
fveFieldError {
_id "invalidMessage-validation"
_style "display:none"
_dataShow "$_invalid_message_error"
_dataText "$_invalid_message_error"
}
}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 readOnlyNotes =
fveField {
fveLabel { _for "readOnlyNotes"; "Read-only notes" }
fveTextarea {
_id "readOnlyNotes"
_name "readOnlyNotes"
_value "Please include reference ITEM-2048."
_readonly true
}
}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 unavailableNotes =
fveField {
fveLabel {
_for "unavailableNotes"
"Unavailable notes"
}
fveTextarea {
_id "unavailableNotes"
_name "unavailableNotes"
_disabled true
}
}This example also uses Field. See their Installation sections for any additional setup.
API reference
module TextareaDsl =
val fveTextarea : ComponentElementBuilder