FancyForms is a library for building forms in Elm. It is designed with the following goals in mind:
Msg and one field on the model.Defines a new form that fields can be added to. Takes four arguments: 1, A unique id for the form to be used as id in the DOM
A validator function that takes the form data and returns a list of errors
A function that receives the fields and returns the view and combine functions
A function that receives the markup of a field and combines it with a list of errors
myForm : Form Int ()
myForm =
Form.form "minimal-example"
(\data -> [])
(\errors_ html -> html)
(\amount ->
{ view = \formState _ -> amount.view formState
, combine = \formState -> amount.value formState
}
)
|> field (integerInput [])Adds a new field with the given widget to the form
Returns true if the data entered in the form is valid
Adds a validator to a widget.
A function that recieves the markup of a field and combines with a list of errors.
The message type for the form.
Updates the form state based on the form message.
Takes the following three arguments to display a form:
a function to turn the forms messages into a Msg of the application.
the form
the current state of the form
type Msg = ... | ForForm Form.Msg | ... type alias Model = { ... , formState : FormState, .. } myForm = Form.form ...
view model = div [] <| Form.render ForForm myForm model.formState
Returns the result of the combine function aka the current state of the form.
Adds a field to the form where the user can add and remove elements.
The first argument is a ListWithAddButton function that cobines the inout list with a button to add a new element.
The second argument is a FieldWithRemoveButton function that combines one item with a button to remove it.
The third argument is the widget to use for each element in the list.
A function that recieves the markup of a list item and combines it with a butoon to remive it from the List.
A function that recieves the markup of a field and combines it with a button to add a new item.
Adds a new field to with different variants to the form. Each variant is represented by a label and a sub form.
The function takes the following arguments:
A widget to select the variant
The default variant
A list of other variants
A variant for widgets with a "select" notion.
A nonempty list of variants.
Creates a new Widget that's decorated with the given function.
A form that collects a value of type
dataand potentially produces errors of typecustomError.