Learn / Errors and failures

Forms

foldkit-form decides when a field's error shows, so a form never shouts at someone who has not typed yet:

  • An edit checks the key at once. Leaving a field says nothing new, so tabbing through a required field shows no Required.
  • A submit checks every key and sets model.attempted. Only then does a foldkit-mixins-form view of more than one control draw the list of fields to fix above the submit button. That list is the one role="alert" for those failures; the errors beside the fields drop their own while it is drawn.
  • Message.Validated({ key }) judges one key as it stands, edited or not: for a stored value shown after a fill, which validates nothing.
  • A rule spanning keys fails on submit, into model.errors. An Entity invariant is judged on submit when the form sets every field it reads, and shows beside each key its path names; one it cannot judge, the server does.

For const RenameForm = Form.make('Rename', Entity.input(Post, RenameInput)), placed at model.renameForm:

ts
RenameForm.attempted(model.renameForm) // a submit was asked: the fields to fix are drawn
RenameForm.Message.Validated({ key: 'title' }) // judge one key now, edited or not
RenameForm.Message.Refused({ key: 'title', error: 'That title is taken' }) // a server's word, on its key

Refused lands whatever state the key is in, and holds until the key is edited. foldkit-crud's editor sends it for you: a save refused with Refusal.field shows the reason on that key, and one refused with Refusal.invalid shows its message beside each key its path names. Any other refusal is the editor's status (SaveFailed, Conflict) and saveError. See Validation and the editor's status.