Tag input
Add and remove submitted text tags with native labels, validation, and read-only states.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let tagInputExample =
fveField {
fveLabel {
_for "item-tags"
"Tags"
}
fveTagInput {
_id "item-tags"
_name "tags"
_values []
}
}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 tag-input --config src/Acme.Components/fve.jsonAdd to src/Acme.Web/js/app.js once, alongside your other component imports:
import '../../Acme.Components/Components/Assets/tag-input.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 tagInputExample =
fveField {
fveLabel {
_for "item-tags"
"Tags"
}
fveTagInput {
_id "item-tags"
_name "tags"
_values []
}
}Submission
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let tagInputFormRegion values (validation: string option) (result: string option) =
div {
_id "components-tag-form-region"
_class "grid gap-3"
form {
_class "grid gap-3"
_dataOn ("submit", "@post('/components/tags', {contentType: 'form'})")
fveField {
fveLabel {
_for "submitted-tags"
"Submitted tags"
}
fveTagInput {
_id "submitted-tags"
_name "submittedTags"
_values values
_ariaInvalid validation.IsSome
_ariaDescribedby (
String.concat
" "
[ "submitted-tags-help"
if validation.IsSome then
"submitted-tags-error" ]
)
}
fveFieldDescription {
_id "submitted-tags-help"
"Choose one to five tags."
}
match validation with
| Some message ->
fveFieldError {
_id "submitted-tags-error"
message
}
| None -> ()
}
fveButton {
_type "submit"
"Save tags"
}
fveButton {
_type "button"
_dataOn ("click", "@get('/components/tags/reset')")
"Reset tags from server"
}
}
match result with
| Some message ->
output {
_role "status"
message
}
| None -> ()
}This example also uses Field, Button. 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 invalidTagInputExample =
fveField {
fveLabel {
_for "required-tags"
"Required tags"
}
fveTagInput {
_id "required-tags"
_name "requiredTags"
_ariaRequired true
_ariaInvalid true
_ariaDescribedby "required-tags-help required-tags-error"
}
fveFieldDescription {
_id "required-tags-help"
"Add at least one classification."
}
fveFieldError {
_id "required-tags-error"
"Add a tag before continuing."
}
}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 pendingTagInputExample =
fveField {
fveLabel {
_for "pending-tags"
"Updating tags"
}
fveTagInput {
_id "pending-tags"
_name "pendingTags"
_values [ "reviewed" ]
_readonly true
_ariaBusy 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 disabledTagInputExample =
fveField {
fveLabel {
_for "disabled-tags"
"Unavailable tags"
}
fveTagInput {
_id "disabled-tags"
_name "disabledTags"
_values [ "archived" ]
_disabled true
}
}This example also uses Field. See their Installation sections for any additional setup.
API reference
module TagInputDsl =
val fveTagInput : ComponentElementBuilder