Features
Fable.Form.Simple.Fields.Html provides a set of common HTML fields that can be used by libraries targetting the browser.
Thanks to it, libraries like Fable.Form.Simple.Bulma and Fable.Form.Simple.Sutil.Bulma can focus on the layout and styling of the fields.
Available Fields
- RangeField
- CheckboxField
- SearchField
- ColorField
- SelectField
- DateField
- TelField
- DateTimeLocalField
- TextField
- EmailField
- TextareaField
- TimeField
- NumberField
- PasswordField
- RadioField
Field Structure
All the fields are following the same definition pattern and can be used in the same way.
Create a module with name of the field.
module ColorField =Define the
Attributestype which contains all the information that can be used to customize the field, and implement theField.IAttributesinterface.[<NoComparison>] type Attributes = { FieldId: string /// <summary> /// Label to display /// </summary> Label: string /// <summary> /// List of predefined colors to display /// </summary> Suggestions: string list option } interface Field.IAttributes with member this.GetFieldId() = this.FieldIdCreate a specialized version of the
Field.Fieldtype where we specify theAttributestype and the type used to represent the field value in the View layer.Example:
ColorFieldusestringto represent the color valueSelectFielduseOptionItem optionto represent the selected item (Noneif nothing is selected)
type InnerField<'Values> = Field.Field<Attributes, string, 'Values>A
formfunction where we specify how to detect if the fieldisEmpty.let form<'Values, 'Field, 'Output> : ((InnerField<'Values> -> 'Field) -> Base.FieldConfig<Attributes, string, 'Values, 'Output> -> Base.Form<'Values, 'Output, 'Field>) = Base.field System.String.IsNullOrEmptyA Pipeline builder API making it easier to create an
Attributesinstance.This is helpful, when your
Attributestype has a lot of fields, instead of having to specify all of them, you can use the builder API to specify only the fields you need.type ColorField = static member create(fieldId: string) : ColorField.Attributes = { FieldId = fieldId Label = "" Suggestions = None } static member withLabel (label: string) (attributes: ColorField.Attributes) = { attributes with Label = label } static member withSuggestions (suggestions: string list) (attributes: ColorField.Attributes) = { attributes with Suggestions = Some suggestions }