Skip to content

Visibility ​

What a definition's conditions hide, as the builder's getVisibility() gives it.

Definition ​

  • Visibility
    • conditional boolean: true when what is hidden depends on the input
    • of (input: unknown) => VisibilityState: the state for an input. The same object while what is hidden stays the same
    • clear <T>(input: T) => T: the input with the fields its conditions clear made blank

Explanation ​

Set each field of toClear with Formisch's setInput, in an effect. The schema blanks their output either way. See conditions.

VisibilityState ​

  • VisibilityState
    • isHidden (node: FieldNode, indexes: readonly number[]) => boolean: whether a field is hidden, by its own conditions or by something it is in
    • isStepHidden (step: LayoutStep) => boolean: whether a step is hidden, by its conditions or because its fields all are
    • shownNodes (nodes: readonly LayoutNode[], indexes: readonly number[], isShown?) => LayoutNode[]: the layout nodes to render, like shownNodes
    • toClear readonly FieldToClear[]: the cleared fields that still hold something

FieldToClear ​

  • FieldToClear
    • path FieldPath: its Formisch path
    • input unknown: undefined, or [] for a list

Example ​

ts
const visibility = builder.getVisibility(definition)

// The form's input now, e.g. Formisch's getInput(form).
const input = { accountType: 'personal', vatId: 'DE123456789' }
const state = visibility.of(input) // the same object until what is hidden changes

const [vatId] = builder
  .getFieldTree(definition)
  .filter((node) => node.field.name === 'vatId')
state.isHidden(vatId!, []) // true
const { toClear } = state // [{ path: ['vatId'], input: undefined }]: set it with Formisch's setInput

Packages ​