Choice cards
Choose one rich option from labelled cards with descriptions and supporting content.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let defaultChoiceCards =
fveChoiceCards {
_id "default-assistance-choice"
fveFieldLegend { "Booking assistance" }
fveChoiceCardsContent {
for value, caption in [ "self", "Self-service"; "staff", "Staff assisted" ] do
fveChoiceCard {
fveRadio {
_name "defaultAssistance"
_value value
}
fveChoiceCardTitle { caption }
}
}
}On this page
Installation
Copy this component and its required dependencies into the consumer-owned Components project.
dotnet fve add choice-cards --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 defaultChoiceCards =
fveChoiceCards {
_id "default-assistance-choice"
fveFieldLegend { "Booking assistance" }
fveChoiceCardsContent {
for value, caption in [ "self", "Self-service"; "staff", "Staff assisted" ] do
fveChoiceCard {
fveRadio {
_name "defaultAssistance"
_value value
}
fveChoiceCardTitle { caption }
}
}
}Single choice
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let richChoiceCards =
fveChoiceCards {
_id "assistance-choice"
fveFieldLegend { "Booking assistance" }
fveChoiceCardsContent {
for value, caption, description, metadata in
[ "self",
"Self-service",
"The participant completes details and waivers before arrival.",
"No staff coordination required"
"staff",
"Staff assisted",
"A coordinator confirms equipment and participant details.",
"Recommended for group bookings"
"unavailable", "Managed service", "Available only to contracted organizations.", "" ] do
fveChoiceCard {
fveRadio {
_name "assistance"
_value value
_required true
if value = "staff" then
_checked true
if value = "unavailable" then
_disabled true
}
fveChoiceCardContent {
fveChoiceCardTitle { caption }
fveChoiceCardDescription { description }
if metadata <> "" then
fveChoiceCardMetadata { metadata }
}
}
}
}Multiple choices
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let multipleChoiceCards =
fveChoiceCards {
_id "equipment-choice"
fveFieldLegend { "Equipment" }
fveChoiceCardsContent {
for value, caption, description in
[ "helmet", "Helmet", "Required protective equipment."
"pads", "Protective pads", "Knee and elbow protection."
"radio", "Trail radio", "Unavailable for this booking." ] do
fveChoiceCard {
fveCheckbox {
_name "equipmentIds"
_value value
if value = "radio" then _disabled true else _checked true
}
fveChoiceCardContent {
fveChoiceCardTitle { caption }
fveChoiceCardDescription { description }
if value = "helmet" then
fveChoiceCardMetadata { "Available" }
}
}
}
}This example also uses Checkbox. See their Installation sections for any additional setup.
Validation
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let invalidChoiceCards =
fveChoiceCards {
_id "invalid-assistance-choice"
_ariaInvalid true
_ariaDescribedby "invalid-assistance-error"
fveFieldLegend { "Booking assistance" }
fveChoiceCardsContent {
for value, caption in [ "self", "Self-service"; "staff", "Staff assisted" ] do
fveChoiceCard {
fveRadio {
_name "invalidAssistance"
_value value
_required true
_ariaInvalid true
_ariaDescribedby "invalid-assistance-error"
}
fveChoiceCardTitle { caption }
}
}
fveFieldError {
_id "invalid-assistance-error"
"Choose how this booking will be supported."
}
}API reference
module ChoiceCardsDsl =
val fveChoiceCards : ComponentElementBuilder
val fveChoiceCardsContent : ComponentElementBuilder
val fveChoiceCard : ComponentElementBuilder
val fveChoiceCardContent : ComponentElementBuilder
val fveChoiceCardTitle : ComponentElementBuilder
val fveChoiceCardDescription : ComponentElementBuilder
val fveChoiceCardMetadata : ComponentElementBuilder
val fveChoiceCardMedia : ComponentElementBuilder