Skip to main content

Field

Own labels, descriptions, validation, orientation, and custom form-control composition.

Default

On this page

Installation

Copy this component and its required dependencies into the consumer-owned Components project.

dotnet fve add field --config src/Acme.Components/fve.json

The CLI resolves dependencies and preserves consumer-authored files. See Installation for project initialization and Tailwind source detection.

Usage

open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar

let defaultField =
    Field.create "reference" "Reference"
    |> Field.render (fun attributes ->
        input {
            for attribute in attributes do attribute
            _name "reference"
            _class "min-h-[var(--fve-control-min-height)] w-full rounded-[var(--fve-radius-control)] border border-[var(--fve-border)] bg-[var(--fve-surface)] px-3 focus-visible:outline-2 focus-visible:outline-[var(--fve-brand-ring)]"
        })

Custom control

Enter the amount before fees.

Responsive label and control rows

Semantic fieldset

Delivery preferences

Choose one or both delivery methods.

API reference

type FieldLayout =
    | Vertical
    | Horizontal
    | Responsive

type FieldConfig

/// Use Field for custom controls. Complete controls such as Input, Textarea and Checkbox
/// already own their labels and must not be nested inside another Field wrapper.
module Field =
    val create : id:string -> label:string -> FieldConfig
    val withDescription : description:string -> config:FieldConfig -> FieldConfig
    val withValidation : message:string -> config:FieldConfig -> FieldConfig
    val withLayout : layout:FieldLayout -> config:FieldConfig -> FieldConfig
    val required : config:FieldConfig -> FieldConfig
    val disabled : config:FieldConfig -> FieldConfig
    val pending : config:FieldConfig -> FieldConfig
    val withAttributes : attributes:HtmlAttribute list -> config:FieldConfig -> FieldConfig
    val render : control:(HtmlAttribute list -> HtmlElement) -> config:FieldConfig -> HtmlElement