formz_string/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(
  fn(Field, Args) -> String,
  Bool,
  Bool,
)

Create a checkbox form input. Parsed as a Bool. If required, the parsed Bool must be True.

pub fn choices_field(
  variants: List(#(String, a)),
  stub stub: a,
) -> Definition(fn(Field, Args) -> String, 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. The actual values rendered in the <option> tags are the numeric indeces of the items in the list.

Because of how you build formz forms, you need to provide a stub 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(
  fn(Field, Args) -> String,
  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(
  fn(Field, Args) -> String,
  Int,
  Option(Int),
)

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

pub fn list_field(
  variants: List(String),
) -> Definition(fn(Field, Args) -> String, 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(
  fn(Field, Args) -> String,
  Float,
  Option(Float),
)

Create a number form input. Parsed as a Float.

pub fn password_field() -> Definition(
  fn(Field, Args) -> String,
  String,
  Option(String),
)

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

pub fn text_field() -> Definition(
  fn(Field, Args) -> String,
  String,
  String,
)

Create a basic form input. Parsed as a String.

Search Document