Skip to content

toFieldPath ​

Gives a field's Formisch path: its dataPath with each '*' replaced by the index of the list item it is in, outermost first.

ts
const path = toFieldPath(dataPath, indexes)

Parameters ​

  • dataPath readonly (string | number)[]
  • indexes readonly number[]

Explanation ​

toFieldPath(['lines', '*', 'quantity'], [2]) is ['lines', 2, 'quantity']. A path with more '*' than indexes is a mistake in the code, so it throws a TypeError. The path comes from the definition at runtime, so pass it to Formisch as never.

Returns ​

FieldPath ​

ts
type FieldPath = readonly (string | number)[]

A field's Formisch path, with real indexes: ['lines', 0, 'quantity'].

Guides ​

Types ​