Skip to main content

Module form

Module form 

Source
Expand description

One focus convention for every form and dialog.

A form is an ordered list of fields, each of a FieldKind. A modal says which fields it shows right now and which one has focus (Form); this module moves focus and decides what a key means, so every dialog answers the same keys the same way:

KeyDoes
Tab / Shift+Tab, ↓ / ↑next / previous field, wrapping
← / →step a choice; move the cursor in a text field
Spacetoggle a checkbox, next value of a choice, open a picker, press a button
Entersubmit, from any field (a multiline field types it; Ctrl+J submits)
Esccancel the form (an open picker closes first: picker_key)
Ctrl+P / Ctrl+Nhistory in a text field

h j k l are the arrows on a field that does not type. What a submit, a step or an action does stays with the modal: key says which happened, to which field.

Enums§

FieldKind
How a field takes keys.
FormKey
What a key did to a form, for the modal to carry out.
ListMove
A move of a list’s cursor, from the keys every list answers: ↑ / k, ↓ / j, PageUp, PageDown, Home and End.
PickerKey
What a key did in an open picker.

Traits§

Form
A form: its fields in order and the one with focus. The modal owns both; the default methods move focus the same way for every form.

Functions§

key
What event does to form while no picker is open. Focus moves happen here; everything else is returned for the modal to do.
picker_form_key
event in a form with a picker open: the picker takes it (picker_key), choosing, toggling or closing through the form. Returns whether a picker was open.
picker_key
What event does in an open picker: type to narrow, ↑↓ move, Space chooses (or toggles in a list of several), Enter chooses, Esc closes the picker only. In a pick-one list Space chooses only while the filter is empty, and types a space once it narrows, so a name of several words can be typed; with nothing typed it would match nothing and blank the list under the key that opened it.
step_index
Index at stepped by delta through len values, wrapping.
step_value
current stepped by delta through all, wrapping; the first value when current is not among them.