cheatcode / joystick

A full-stack JavaScript framework for building stable, easy-to-maintain apps and websites.
https://cheatcode.co/joystick
Other
209 stars 11 forks source link

Add ability to specify validation rules as functions #377

Open rglover opened 5 months ago

rglover commented 5 months ago

The function should receive the entirety of the input from the client, returning a validation rule. The idea being to make it so that a developer can conditionally apply rules based on other input. For example, if the payment provider is stripe, make the source field required: true, otherwise, required: false.

input: {
  provider: {
    type: 'string',
    allowed_values: ['paypal', 'stripe'],
    required: true,
  },
  source: (input = {}) => ({
    type: 'string',
    required: input?.provider === 'stripe'
  }),
}