Skip to content

defineFormRule ​

Defines a form rule. It returns the form rule unchanged, typed so that reads() and check() get its params parsed.

ts
const formRule = defineFormRule<TParams>(def)

Generics ​

Parameters ​

Explanation ​

Register the form rule with createSchemaBuilder's formRules option, under the name definitions use in rule.

Returns ​

Example ​

ts
const sameZip = defineFormRule({
  params: v.object({ others: v.array(v.string()) }),
  reads: (params) => params.others,
  kinds: ['string'],
  // The value of `field`, then the values of the paths `reads` gives.
  check: (values) => new Set(values).size === 1,
  meta: { label: 'Same ZIP', category: 'comparison' },
})

const withFormRule = createSchemaBuilder({ formRules: { sameZip } })

Guides ​

Types ​