• Stars
    star
    200
  • Rank 195,325 (Top 4 %)
  • Language
    Elm
  • License
    BSD 3-Clause "New...
  • Created over 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build type-safe composable forms in Elm

composable-form Build Status

This package allows you to build forms that are

  • Composable: they can be extended and embedded in other forms.
  • Type-safe: everything is safely tied together with compiler guarantees.
  • Maintainable: you do not need view code nor a msg for each form field.
  • Concise: field validation and update logic are defined in a single place.
  • Consistent: validation errors are always up-to-date with the current field values.
  • Extensible: you can create your own custom fields and write custom view code.

Here is an example that defines a login form:

module Form.Login exposing (Output, Values, form)

import EmailAddress exposing (EmailAddress)
import Form exposing (Form)


type alias Values =
    { email : String
    , password : String
    , rememberMe : Bool
    }


type alias Output =
    { email : EmailAddress
    , password : String
    , rememberMe : Bool
    }


form : Form Values Output
form =
    let
        emailField =
            Form.emailField
                { parser = EmailAddress.parse
                , value = .email
                , update = \value values -> { values | email = value }
                , error = always Nothing
                , attributes =
                    { label = "E-Mail"
                    , placeholder = "[email protected]"
                    }
                }

        passwordField =
            Form.passwordField
                { parser = Ok
                , value = .password
                , update = \value values -> { values | password = value }
                , error = always Nothing
                , attributes =
                    { label = "Password"
                    , placeholder = "Your password"
                    }
                }

        rememberMeCheckbox =
            Form.checkboxField
                { parser = Ok
                , value = .rememberMe
                , update = \value values -> { values | rememberMe = value }
                , error = always Nothing
                , attributes =
                    { label = "Remember me" }
                }
    in
    Form.succeed Output
        |> Form.append emailField
        |> Form.append passwordField
        |> Form.append rememberMeCheckbox

Read the Form module documentation to understand how this code works.

Demo / Examples

Try out the live demo and/or check out the examples.

Also, feel free to play with the package using this Ellie snippet.

Contributing / Feedback

Feel free to fork and open issues or pull requests. You can also come to chat in the #forms channel on the Elm Slack, feel free to contact me (@hecrj) there!

More Repositories

1

coffee

An opinionated 2D game engine for Rust
Rust
1,072
star
2

wgpu_glyph

A fast text renderer for wgpu (https://github.com/gfx-rs/wgpu)
Rust
449
star
3

zelda

A Zelda clone in C++
C
154
star
4

setup-rust-action

Set up a specific Rust toolchain in your GitHub workflows
Shell
103
star
5

html-parser

Parse HTML 5 in Elm
Elm
61
star
6

icebreaker

A local AI chat app powered by πŸ¦€ Rust, 🧊 iced, πŸ€— Hugging Face, and πŸ¦™ llama.cpp
Rust
39
star
7

window_clipboard

A library to obtain clipboard access from a `raw-window-handle`.
Rust
21
star
8

glow_glyph

A fast text renderer for glow (https://github.com/grovesNL/glow)
Rust
13
star
9

elm-slug

Type-safe slugs for Elm
Elm
10
star
10

download-release-action

Download the assets of a GitHub release
TypeScript
5
star
11

reticular

Lightweight Python module for creating powerful command-line tools
Python
4
star
12

piet-window

A simple crate to obtain a Piet renderer from a raw-window-handle
Rust
3
star
13

SwiftDecodePipeline

A library for building JSON decoders using the pipeline operator. Inspired by https://github.com/NoRedInk/elm-decode-pipeline.
Swift
3
star
14

idi

Interaction and Design of Interfaces - FIB - Fall 2013
Makefile
3
star
15

fast

A command-line tool to test the optimizations performed to a program.
Python
3
star
16

jtest

Tool for automatic testing and creating problems from Jutge.org
Ruby
2
star
17

advent_of_code

My solutions to Advent of Code
Haskell
2
star
18

mmpg

My final project for the computer science degree at FIB
TeX
2
star
19

rom-filesystem

Filesystem adapter for ROM
Ruby
1
star
20

words

words is a simple program that estimates the number of different words that a file contains.
TeX
1
star
21

alg

Algorithmics - FIB - Fall 2013
C++
1
star
22

eda

Estructuras de Datos y Algoritmos - FIB - UPC - 2012
C++
1
star
23

haskell-format

A highly opinionated Haskell formatter
Haskell
1
star
24

ies

No more sequence diagrams!
Java
1
star