Skip to content

feat: effect/schema form resolver #174

@tomsour1s

Description

@tomsour1s

I am currently working on a project where we heavily use the effect/schema library. To avoid adding another dependency for form validation, I have implemented a new resolver.

I believe this could be interesting and useful for others as well.
Would you consider accepting a merge request that adds this new resolver?

Here is a quick demo of how it works so far:

  1. define a schema
const FORM_SCHEMA = Schema.Struct({
  id: Schema.String,
  startDate: Schema.DateFromSelf,
  endDate: Schema.DateFromSelf.pipe(
    Schema.annotations({ message: () => 'Please inter a valid Date or select a Date with the DatePicker' }),
  ),
  reason: Schema.String.pipe(
    Schema.minLength(4),
    Schema.annotations({ message: () => 'Has to be at least 4 chars long' }),
  ),
})
  1. use the custom resolver with full support of the ParseOptions Object from effect/schema
const resolver = ref(effectSchemaResolver(FORM_SCHEMA, { errors: 'all' }))
  1. example of the error message
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Needs TriageIssue will be reviewed by Core Team and a relevant label will be added as soon as possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions