formz_lustre/definitions

Hopefully these are pretty self-explanatory. I haven’t provided any examples here, as these are all used to build HTML forms and I don’t know how helpful it would be to see the raw HTML. If you’d like to see examples of these in action, please see the formz_demo example project.

Functions

pub fn boolean_field() -> Definition(Element(a), Bool, Bool)

Create a checkbox form input. Parsed as a Boolean.

pub fn choices_field(
  variants: List(#(String, a)),
  stub stub: a,
) -> Definition(Element(b), a, Option(a))

Creates a <select> input. Takes a tuple of #(String, String) where the first item in the tuple is the label, and the second item can be any Gleam type and is the value that would be parsed for a given selection.

Because of how you build formz forms, you need to provide a placeholder of the value type. Is this annoying? Would it be more or less annoying if I required a non-empty list for the variants instead? I’m not sure. Let me know!

pub fn email_field() -> Definition(
  Element(a),
  String,
  Option(String),
)

Create an email form input. Parsed as a String but must look like an email address, i.e. the string has an @.

pub fn integer_field() -> Definition(Element(a), Int, Option(Int))

Create a whole number form input. Parsed as an Int.

pub fn list_field(
  variants: List(String),
) -> Definition(Element(a), String, Option(String))

Creates a <select> input from a list of strings. Validates that the parsed value is one of the strings in the list.

pub fn number_field() -> Definition(
  Element(a),
  Float,
  Option(Float),
)

Create a number form input. Parsed as a Float.

pub fn password_field() -> Definition(
  Element(a),
  String,
  Option(String),
)

Create a password form input, which hides the input value. Parsed as a String

pub fn text_field() -> Definition(Element(a), String, String)

Create a basic form input. Parsed as a String.

Search Document