Checkbox
Submit a checked native value with explicit Field labels and feedback. Unchecked controls follow native form semantics.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let basicCheckbox =
fveField {
_layout FieldLayout.Horizontal
fveCheckbox {
_id "emailUpdates"
_name "emailUpdates"
}
fveLabel {
_for "emailUpdates"
"Email me product updates"
}
}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 checkbox --config src/Acme.Components/fve.jsonAdd to src/Acme.Web/js/app.js once, alongside your other component imports:
import '../../Acme.Components/Components/Assets/checkbox.js';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 basicCheckbox =
fveField {
_layout FieldLayout.Horizontal
fveCheckbox {
_id "emailUpdates"
_name "emailUpdates"
}
fveLabel {
_for "emailUpdates"
"Email me product updates"
}
}With help text
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let checkboxWithHelp =
fveField {
_layout FieldLayout.Horizontal
fveCheckbox {
_id "includeSummary"
_name "includeSummary"
_ariaDescribedby "includeSummary-description"
}
fveFieldContent {
fveLabel {
_for "includeSummary"
"Include a summary"
}
fveFieldDescription {
_id "includeSummary-description"
"Add a short overview at the beginning of the report."
}
}
}This example also uses Field. See their Installation sections for any additional setup.
Indeterminate
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let indeterminateCheckbox =
fveField {
_layout FieldLayout.Horizontal
fveCheckbox {
_id "mixedSelection"
_name "mixedSelection"
_indeterminate true
}
fveLabel {
_for "mixedSelection"
"Select all items"
}
}This example also uses Field. See their Installation sections for any additional setup.
Required confirmation with validation
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let choiceSubmitButton id (label: string) =
fveButton {
_color Color.Primary
_variant ButtonVariant.Solid
_type "submit"
_id id
label
}
let choiceResult id result =
output {
_id id
_role "status"
_class "block min-h-5 text-sm text-[var(--fve-muted-text)]"
defaultArg result "Submit the form to see the result."
}
let checkboxFormRegion confirmed (validation: string option) result =
div {
_id "components-checkbox-form-region"
_class "grid max-w-sm gap-3"
form {
_novalidate true
_dataOn ("submit", "@post('/components/choices/checkbox', {contentType: 'form'})")
_class "grid gap-3"
fveField {
_layout FieldLayout.Horizontal
fveCheckbox {
_id "components-confirm-archived-review"
_name "confirmArchivedReview"
_required true
_checked confirmed
_ariaInvalid validation.IsSome
_ariaDescribedby (
String.concat
" "
[ "confirmed-description"
if validation.IsSome then
"confirmed-validation" ]
)
}
fveFieldContent {
fveLabel {
_for "components-confirm-archived-review"
"Confirm review"
}
fveFieldDescription {
_id "confirmed-description"
"Required before continuing."
}
match validation with
| Some message ->
fveFieldError {
_id "confirmed-validation"
message
}
| None -> ()
}
}
choiceSubmitButton "components-checkbox-submit" "Validate confirmation"
}
choiceResult "components-checkbox-result" result
}This example also uses Field, Button. See their Installation sections for any additional setup.
Checked
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let includeArchived =
fveField {
_layout FieldLayout.Horizontal
fveCheckbox {
_id "includeArchived"
_name "includeArchived"
_checked true
_ariaDescribedby "includeArchived-description"
}
fveFieldContent {
fveLabel {
_for "includeArchived"
"Include archived items"
}
fveFieldDescription {
_id "includeArchived-description"
"Archived items remain read-only."
}
}
}This example also uses Field. See their Installation sections for any additional setup.
Pending
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let pendingArchivedReview =
fveField {
_layout FieldLayout.Horizontal
fveCheckbox {
_id "components-pending-archived-review"
_name "confirmArchivedReview"
_checked true
_readonly true
_ariaBusy true
}
fveLabel {
_for "components-pending-archived-review"
"Saving review"
}
}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 disabledArchivedReview =
fveField {
_layout FieldLayout.Horizontal
fveCheckbox {
_id "components-disabled-archived-review"
_name "confirmArchivedReview"
_disabled true
}
fveLabel {
_for "components-disabled-archived-review"
"Archived review unavailable"
}
}This example also uses Field. See their Installation sections for any additional setup.
API reference
module CheckboxDsl =
val fveCheckbox : ComponentElementBuilder
module CheckboxAttributes =
val Html._indeterminate.Static : value:bool -> HtmlAttribute