Documentation
Form

Form

Form offers a developer-friendly and organized approach to designing forms with built-in validation.

Usage Example

n.form(
  {
    id = "form",
    submit_key = "<S-CR>",
    on_submit = function(is_valid)
      print(is_valid)
    end,
  },
  n.text_input({
    autofocus = true,
    autoresize = true,
    size = 1,
    border_label = "Title",
    max_lines = 5,
    validate = n.validator.min_length(3),
  }),
  n.text_input({
    flex = 1,
    border_label = "Description",
    validate = n.validator.compose(n.validator.min_length(4), n.validator.max_length(20)),
  })
)

Properties

on_submit

Default value
fn.ignore
Type
fun(is_valid: boolean): nil

submit_key

Default value
<C-CR>
Type
string[] | string

Validators

PRs with new validators are welcome!

Available validation functions:

  • min_length
  • max_length
  • equals
  • contains

Available combinators:

  • all: ensures all validators pass
  • any: ensures at least one validator passes
  • none: ensures no validators pass
  • compose: alias for all