canceraiddev / elm-form-builder / Form.Field

Field type and helper functions

Field


type Field
    = StringField_ StringField
    | MultiStringField_ MultiStringField
    | BoolField_ BoolField
    | IntegerField_ IntegerField


type StringField
    = SimpleField SimpleFieldProperties
    | DateField DateFieldProperties
    | SelectField (SelectFieldProperties {})
    | SearchableSelectField SearchableSelectFieldProperties
    | HttpSelectField HttpSelectFieldProperties
    | RadioField RadioFieldProperties


type MultiStringField
    = MultiSelectField (MultiSelectFieldProperties {})
    | SearchableMultiSelectField SearchableMultiSelectFieldProperties
    | MultiHttpSelectField MultiHttpSelectFieldProperties
    | TagField TagFieldProperties


type BoolField
    = CheckboxField CheckboxFieldProperties
    | RadioBoolField RadioBoolFieldProperties
    | RadioEnumField RadioEnumFieldProperties


type IntegerField
    = IntegerField IntegerFieldProperties

Properties


type alias CommonFieldProperties =
FieldProperties {}


type alias DateFieldProperties =
StringFieldProperties { tipe : FieldType.DateFieldType
, parsedDate : Maybe Time.Posix 
}


type alias SimpleFieldProperties =
StringFieldProperties { tipe : FieldType.SimpleFieldType
, regexValidation : List Form.Lib.RegexValidation.RegexValidation 
}


type alias SelectFieldProperties a =
StringFieldProperties { a | default : Maybe String
, options : List Option
, placeholder : String
, hasSelectablePlaceholder : Basics.Bool 
}


type alias SearchableSelectFieldProperties =
SelectFieldProperties { showDropdown : Basics.Bool
, searchInput : String 
}


type alias HttpSelectFieldProperties =
StringFieldProperties { url : String
, default : Maybe String
, options : RemoteData (Http.Detailed.Error String) (List Option)
, placeholder : String
, hasSelectablePlaceholder : Basics.Bool 
}


type alias MultiSelectFieldProperties a =
MultiStringFieldProperties { a | placeholder : String
, showDropdown : Basics.Bool
, options : List Option 
}


type alias SearchableMultiSelectFieldProperties =
MultiSelectFieldProperties { searchableOptions : List Option
, searchInput : String 
}


type alias MultiHttpSelectFieldProperties =
MultiStringFieldProperties { placeholder : String
, showDropdown : Basics.Bool
, url : String
, options : RemoteData (Http.Detailed.Error String) (List Option) 
}


type alias RadioFieldProperties =
StringFieldProperties { default : Maybe String
, options : List Option
, direction : Direction 
}


type alias BoolFieldProperties a =
FieldProperties { a | value : Basics.Bool }


type alias CheckboxFieldProperties =
BoolFieldProperties { tipe : FieldType.CheckboxFieldType }


type alias RadioBoolFieldProperties =
FieldProperties { value : Maybe Basics.Bool }


type alias RadioEnumFieldProperties =
FieldProperties { value : Maybe RadioEnum.Value
, default : Maybe RadioEnum.Value
, options : List RadioEnum.Value 
}


type alias StringFieldProperties a =
FieldProperties { a | value : String }


type alias TagFieldProperties =
MultiStringFieldProperties { inputBar : String
, placeholder : Maybe String 
}


type alias FieldProperties a =
{ a | required : Required.IsRequired
, label : String
, width : Width
, enabledBy : Maybe String
, order : Basics.Int
, disabled : Basics.Bool
, hidden : Basics.Bool
, unhiddenBy : Maybe String 
}


type alias IntegerFieldProperties =
FieldProperties { tipe : FieldType.IntegerFieldType
, value : Maybe Basics.Int 
}

Default Properties

integerDefault : IntegerFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , tipe = { min = Nothing, max = Nothing } , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = Nothing }

checkboxDefault : CheckboxFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = False , tipe = FieldType.Checkbox }

dateDefault : DateFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , tipe = { min = Nothing, max = Nothing } , value = "" , parsedDate = Nothing }

emailDefault : SimpleFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , regexValidation = [] , tipe = FieldType.Email , value = "" }

httpSelectDefault : HttpSelectFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = "" , url = "" , default = Nothing , options = RemoteData.NotAsked , placeholder = "" , hasSelectablePlaceholder = False }

searchableSelectDefault : SearchableSelectFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = Set.empty , options = [] , placeholder = "" , showDropdown = False , searchableOptions = [] , searchInput = "" }

multiHttpSelectDefault : MultiHttpSelectFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = Set.empty , options = RemoteData.NotAsked , placeholder = "" , showDropdown = False , url = "" }

multiSelectDefault : MultiSelectFieldProperties {}

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = Set.empty , options = [] , placeholder = "" , showDropdown = False }

phoneDefault : SimpleFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , regexValidation = [] , tipe = FieldType.Phone , value = "" }

timeDefault : SimpleFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , regexValidation = [] , tipe = FieldType.Time , value = "" }

radioBoolDefault : RadioBoolFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = Nothing }

radioDefault : RadioFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = "" , default = Nothing , options = [] , direction = Direction.Column }

radioEnumDefault : RadioEnumFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = Nothing , default = Nothing , options = [ RadioEnum.Yes, RadioEnum.No, RadioEnum.NA ] }

searchableMultiSelectDefault : SearchableMultiSelectFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = Set.empty , options = [] , placeholder = "" , showDropdown = False , searchableOptions = [] , searchInput = "" }

selectDefault : SelectFieldProperties {}

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = "" , default = Nothing , options = [] , placeholder = "" , hasSelectablePlaceholder = False }

tagDefault : TagFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , value = Set.empty , inputBar = "" , placeholder = Nothing }

textAreaDefault : SimpleFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , regexValidation = [] , tipe = FieldType.TextArea , value = "" }

textDefault : SimpleFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , regexValidation = [] , tipe = FieldType.Text , value = "" }

urlDefault : SimpleFieldProperties

{ required = Required.No , label = "" , width = Width.FullSize , enabledBy = Nothing , order = 0 , disabled = False , hidden = False , unhiddenBy = Nothing , regexValidation = [] , tipe = FieldType.Url , value = "" }

Constructors

integer : IntegerFieldProperties -> Field

Makes an age input field.

Common builders:

checkbox : CheckboxFieldProperties -> Field

Makes a checkbox field.

Common builders:

date : DateFieldProperties -> Field

Makes a date input field. By default, dates 100 years from the start of the Unix epoch (00:00:00 UTC on 1 January 1970) are allowed. Use setters to customise this.

In addition to the common builders, the following are available:

Common builders:

httpSelect : String -> HttpSelectFieldProperties -> Field

Makes a remotely fetched drop-down select field.

In addition to the common builders, the following are available:

Common builders:

text : SimpleFieldProperties -> Field

Makes an input field, defaulting to text input.

In addition to the common builders, the following are available:

Common builders:

multiHttpSelect : String -> MultiHttpSelectFieldProperties -> Field

Makes a remotely fetched multi select field.

In addition to the common builders, the following are available:

Common builders:

multiSelect : List Option -> MultiSelectFieldProperties {} -> Field

Makes a multi select field from a list of options.

In addition to the common builders, the following are available:

A list of options needs to be passed in, but setters passed in will override these.

Common builders:

radio : List Option -> RadioFieldProperties -> Field

Makes a radio field.

In addition to the common builders, the following are available:

A list of options needs to be passed in, but setters passed in will override these.

Common builders:

radioBool : RadioBoolFieldProperties -> Field

Makes a boolean radio field.

Common builders:

radioEnum : RadioEnumFieldProperties -> Field

Makes a radio field for selection of Yes/No/N/A enums, with all three as an option by default. Override with setOptions.

In addition to the common builders, the following are available:

Common builders:

searchableSelect : SearchableSelectFieldProperties -> Field

Makes a searchable select field, with options that are searchable.

In addition to the common builders, the following are available:

Common builders:

searchableMultiSelect : SearchableMultiSelectFieldProperties -> Field

Makes a searchable multi select field, with two categories of options: searchable and non-searchable. Neither category is mandatory, so make sure to set at least one for the field to be useful.

In addition to the common builders, the following are available:

Common builders:

select : List Option -> SelectFieldProperties {} -> Field

Makes a drop-down select field from a list of options.

In addition to the common builders, the following are available:

A list of options needs to be passed in, but setters passed in will override these.

Common builders:

tag : TagFieldProperties -> Field

Makes a tag field.

In addition to the common builders, the following are available:

Common builders:

url : SimpleFieldProperties -> Field

Makes a url field.

In addition to the common builders, the following are available:

Common builders:

phone : SimpleFieldProperties -> Field

Makes a phone field.

In addition to the common builders, the following are available:

Common builders:

time : SimpleFieldProperties -> Field

Makes a time field.

In addition to the common builders, the following are available:

Common builders:

textArea : SimpleFieldProperties -> Field

Makes a multiline text area field.

In addition to the common builders, the following are available:

Common builders:

email : SimpleFieldProperties -> Field

Makes an email input field.

In addition to the common builders, the following are available:

Common builders:

Construction Property Setters

setDateFuture : DateFieldProperties -> DateFieldProperties

Sets the selectable date range to be the next 10 years.

setDateOfBirth : DateFieldProperties -> DateFieldProperties

Sets the selectable date range to be the last 120 years.

setDatePast : DateFieldProperties -> DateFieldProperties

Sets the selectable date range to be the last 120 years.

setMinDate : Time.Posix -> DateFieldProperties -> DateFieldProperties

Sets the max selectable date range to specified absolute date in POSIX time.

setMaxDate : Time.Posix -> DateFieldProperties -> DateFieldProperties

Sets the max selectable date range to specified absolute date in POSIX time.

setMinDateOffset : ( Time.Extra.Interval, Basics.Int ) -> DateFieldProperties -> DateFieldProperties

Sets the max selectable date range to specified interval relative to the current date. For example, to select a min date of 2 years ago, use: setMinDateOffset ( TimeExtra.Year, 2 )

setMaxDateOffset : ( Time.Extra.Interval, Basics.Int ) -> DateFieldProperties -> DateFieldProperties

Sets the max selectable date range to specified interval relative to the current date. For example, to select a max date 5 years from now, use: setMaxDateOffset ( TimeExtra.Year, 5 )

setMin : Basics.Int -> IntegerFieldProperties -> IntegerFieldProperties

Sets the min integer value.

setMax : Basics.Int -> IntegerFieldProperties -> IntegerFieldProperties

Sets the max integer value.

setDefault : d -> FieldProperties { a | default : Maybe d } -> FieldProperties { a | default : Maybe d }

setDirection : Direction -> RadioFieldProperties -> RadioFieldProperties

setDisabled : FieldProperties a -> FieldProperties a

setEnabledBy : String -> FieldProperties a -> FieldProperties a

setForbiddenEmailDomains : List Format.Email.ForbiddenDomain -> SimpleFieldProperties -> SimpleFieldProperties

setHidden : FieldProperties a -> FieldProperties a

setIsRequired : Required.IsRequired -> FieldProperties a -> FieldProperties a

setLabel : String -> FieldProperties a -> FieldProperties a

setOptions : o -> FieldProperties { a | options : o } -> FieldProperties { a | options : o }

setOrder : Basics.Int -> FieldProperties a -> FieldProperties a

setPlaceholder : p -> FieldProperties { a | placeholder : p } -> FieldProperties { a | placeholder : p }

setRegexValidation : List Form.Lib.RegexValidation.RegexValidation -> SimpleFieldProperties -> SimpleFieldProperties

setRemoteUrl : String -> FieldProperties { a | url : String } -> FieldProperties { a | url : String }

setSearchableOptions : List Option -> SearchableMultiSelectFieldProperties -> SearchableMultiSelectFieldProperties

setSelectablePlaceholder : FieldProperties { a | hasSelectablePlaceholder : Basics.Bool } -> FieldProperties { a | hasSelectablePlaceholder : Basics.Bool }

setTagsInputBar : String -> TagFieldProperties -> TagFieldProperties

setUnhiddenBy : String -> FieldProperties a -> FieldProperties a

setValue : v -> FieldProperties { a | value : v } -> FieldProperties { a | value : v }

setWidth : Width -> FieldProperties a -> FieldProperties a

Getters

getBoolProperties : Field -> Maybe Basics.Bool

getEnabledBy : Field -> Maybe String

getUnhiddenBy : Field -> Maybe String

getLabel : Field -> String

getIntegerValue : Field -> Maybe Basics.Int

getOrder : Field -> Basics.Int

getProperties : Field -> CommonFieldProperties

getStringType : StringField -> FieldType.StringFieldType

getStringValue : Field -> Maybe String

getStringValue_ : StringField -> String

getParsedDateValue_ : StringField -> Maybe Time.Posix

getMultiStringValue_ : MultiStringField -> Set String

getType : Field -> FieldType

getUrl : Field -> Maybe String

Setters

resetValueToDefault : Field -> Field

updateBoolValue : Basics.Bool -> Field -> Field

updateCheckboxValue_ : Basics.Bool -> BoolField -> BoolField

updateIntegerValue : String -> Field -> Field

updateIntegerValue_ : Maybe Basics.Int -> IntegerField -> IntegerField

updateRadioBoolValue : Maybe Basics.Bool -> Field -> Field

updateRadioBoolValue_ : Maybe Basics.Bool -> BoolField -> BoolField

updateRadioEnumValue : Maybe RadioEnum.Value -> Field -> Field

updateRadioEnumValue_ : Maybe RadioEnum.Value -> BoolField -> BoolField

updateRemoteOptions : RemoteData (Http.Detailed.Error String) (List Option) -> Field -> Field

updateStringValue : String -> Field -> Field

updateParsedDateValue : Time.Posix -> StringField -> StringField

updateStringDisabled : Basics.Bool -> Field -> Field

updateMultiStringOption : Option -> Basics.Bool -> Field -> Field

updateStringValue_ : String -> StringField -> StringField

updateMultiStringValue_ : Set String -> MultiStringField -> MultiStringField

updateShowDropdown : Basics.Bool -> Field -> Field

maybeUpdateStringValue : Maybe String -> Field -> Field

Keep existing field if the value is Nothing

updateTagsInputBarValue : String -> Field -> Field

updateTagsValue : Basics.Bool -> String -> Field -> Field

updateTagsValue_ : Basics.Bool -> String -> MultiStringField -> MultiStringField

updateSearchableSelectInput : String -> Field -> Field

Predicates

isCheckbox : Field -> Basics.Bool

isRequired : Field -> Required.IsRequired

Encode

encode : Field -> Json.Encode.Value

Metadata

metadataKey : String -> Maybe String