···1616manage, and would like to keep the form markup and parsing logic in sync. It
1717takes some amount of effort to make an actual form generator with markup and
1818styles, and that might not be worth it for a one-off form. That said, a simple
1919-form generator is provided if you aren't opinionated about your markup.
1919+form generator is provided if you aren't opinionated about your markup, and this
2020+author would use this for one off forms himself...
20212122```sh
2223gleam add formz@0.1
+2-1
formz/gleam.toml
···44version = "2.0.1"
55description = "Accessible, type safe form parsing and generating for Gleam"
66licences = ["Unlicense"]
77-repository = { type = "github", user = "bentomas", repo = "formz", path = "formz" }
77+# repository = { type = "tangled", user = "@bthom.tngl.sh", repo = "formz", path = "formz" }
88+repository = { type = "custom", url = "https://tangled.org/@bthom.tngl.sh/formz" }
89gleam = ">= 1.6.0"
9101011[dependencies]
+16-10
formz/src/formz.gleam
···5757//// </td>
5858//// </tr>
5959//// <tr>
6060-//// <td>Accessing and manipulating config for a form item</td>
6060+//// <td>Creating, accessing and manipulating config for a form item</td>
6161//// <td>
6262+//// <a href="#named">named</a><br>
6263//// <a href="#update_config">update_config</a><br>
6364//// <a href="#set_name">set_name</a><br>
6465//// <a href="#set_label">set_label</a><br>
···202203 /// and underscores.
203204 name: String,
204205 /// This library thinks of a label as required, but will make one for you from
205205- /// the name if you don't provide one via the `field` function. For
206206+ /// the name if you don't provide one via the `set_label` function. For
206207 /// accessibility reasons, a field should always provide a label and all
207208 /// the maintained form generators will output one.
208209 label: String,
···463464 case max - num_nonempty {
464465 x if x < 0 -> Error(-x)
465466 _ -> {
466466- int.max(1 - num_nonempty, int.min(extra, max - num_nonempty))
467467 list.fold([1, extra, min], 0, int.max)
468468469469 // if they've specified a minimum required, then start there
···10691069 })
10701070}
1071107110721072-/// Convenience function for setting the `InputState`s of a list field. This
10731073-/// takes a list of Results, where the Ok means the input is `Valid` and
10741074-/// `Error` means the input is `Invalid` with the given error message.
10721072+/// Convenience function for setting the `InputState`s of a list field to an
10731073+/// error. This takes a list of Results, where the Ok means the input *should
10741074+/// not be changed* and `Error` means the input's state should be `Invalid`
10751075+/// with the given error message.
10751076///
10761076-/// This does not clear any existing errors, it will just set the errors marked
10771077-/// in the input list. If you want to clear errors you'll have to use the
10781078-/// `update` function and do it manually.
10771077+/// To be clear, this does not clear any existing errors, it will just set the
10781078+/// errors marked in the input list. If you want to clear errors you'll have
10791079+/// to use the `update` function and do it manually.
10791080///
10801081/// ### Example
10811082///
···11631164/// additional constraints. Like say, requiring a `String` to be at least
11641165/// a certain length, or that an Int must be positive.
11651166///
11671167+/// If you want to chain additional validation and change the return type,
11681168+/// you'll have to create a new definition. There is (currently) no function
11691169+/// for wrapping an existing definition in additional verify logic that changes
11701170+/// either the required or optional type.
11711171+///
11661172/// ### Example
11671173/// ```gleam
11681174/// field
11691169-/// |> validate(fn(i) {
11751175+/// |> verify(fn(i) {
11701176/// case i > 0 {
11711177/// True -> Ok(i)
11721178/// False -> Error("must be positive")