Form / Limits and guards from a metakit declaration

Give money and dates a control that reads them

Declared.inputs(schema) gives each Money, Decimal and CalendarDay key a control that matches its attributes. The example above passed it under inputs. A Money key's draft is the amount in whole units (12.50), stored as cents (1250); a CalendarDay key's draft is the day as YYYY-MM-DD, what an <input type="date"> holds. Without it, a Money key gets the plain Number control, which reads 12.50 as the number 12.5; the Schema stores whole cents, so 12.5 is not a valid stored value and decoding fails.

A control you name for the same key replaces the derived one:

ts
Form.make('Withdraw', Form.input(WithdrawInput), {
  inputs: { ...Declared.inputs(WithdrawInput), amount: Input.text() },
})

For a Money key that should read and write amounts in the reader's locale (1.234,50 €), use the control of FieldRecipes.money({ currency, unit: 'minor' }) from foldkit-form-recipes instead. It stores the same whole minor units, at the scale the currency itself uses.

foldkit-mixins-form draws them with no renderer of yours, once you draw the form from DeclaredView.of(form, Declared.of(form)) (foldkit-mixins-form/declared): a CalendarDay key as a date input (type="date"), and a Money or Decimal key as a text input with the decimal keypad, each with the min, max and step above. To draw one yourself, pass a renderer under renderers, keyed CalendarDay or Decimal; it can tell the controls apart with Declared.CalendarDay.is(control) and Declared.Decimal.is(control), and the Decimal control's data is the domain's own, so it can show a Money key's currency.