Skip to content

About

Define Formisch forms in JSON, render them with your own components, or compile them to typed Valibot code.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

form-builder - forms from JSON, validated by Formisch

form-builder

Describe forms in JSON and get validated Formisch forms out.

CI Coverage License TypeScript Valibot Vue React

Documentation

form-builder turns a JSON form definition into a Valibot schema that Formisch understands, with the fields, validation, layout and conditions it describes. It is meant for forms that don't belong in your source code: forms stored in a database, served by an API or put together in a visual editor. The core is framework-agnostic and works with Formisch's own package for Vue, React, Preact, Solid, Svelte, Qwik and Angular. Headless adapters for Vue and React render the fields with your own components.

Example

A signup form, as a definition:

{
  "version": "1",
  "fields": [
    { "name": "email", "type": "email", "required": true },
    {
      "name": "password",
      "type": "password",
      "required": true,
      "rules": [{ "rule": "minLength", "value": 8 }]
    }
  ]
}

The schema package builds it into a schema for Formisch, or for a plain v.parse:

import { createSchemaBuilder } from '@whatsaaaa/form-builder-schema'

const builder = createSchemaBuilder()
const schema = builder.build(json)

Highlights

  • Every native control as a field type, plus groups, arrays and display elements
  • Every Valibot action that fits in JSON as a validation rule, and form rules across fields
  • Sections, a 12-column grid and multi-step forms, described in the definition
  • Fields, sections and steps that show, hide and clear by the values of other fields
  • Definitions checked with precise issues, and a JSON Schema for editor autocompletion
  • Your own field types, rules and messages, with i18n through Valibot

Packages

Package Description
@whatsaaaa/form-builder-schema Builds Formisch-ready Valibot schemas from JSON definitions. The core.
@whatsaaaa/form-builder-affects Conditions that show, hide and clear fields, sections and steps.
@whatsaaaa/form-builder-fills Fills fields from the value of another, by a map or a source of yours.
@whatsaaaa/form-builder-vue Renders definitions with Formisch and your own Vue components.
@whatsaaaa/form-builder-react Renders definitions with Formisch and your own React components.

Preact, Solid, Svelte, Qwik and Angular need no adapter. The schema package works with Formisch's own package for each, and the docs have a tested renderer for each to start from.

Planned: @whatsaaaa/form-builder-codegen, a CLI that turns definitions into typed TypeScript, and a visual builder that writes definitions.

Status

The schema, Vue and React packages follow semantic versioning from 1.0: the JSON format, the exports, and the codes and paths of issues only break in a major release. The affects and fills packages stay before 1.0 for now. See stability, supported versions, and migrating to 1.0.

1.0 is in release candidates on the rc dist-tag, while a plain install still gives 0.x. To try it, add @rc to each form-builder package you install, for example pnpm add @whatsaaaa/form-builder-schema@rc @whatsaaaa/form-builder-vue@rc @formisch/vue valibot (or @whatsaaaa/form-builder-react@rc @formisch/react, plus @whatsaaaa/form-builder-affects@rc for conditions and @whatsaaaa/form-builder-fills@rc for fills). With pnpm 11 or later, see the installation guide for what @rc needs right after a release candidate comes out. Read the migration guide and stability policy above before you upgrade, and tell us how it goes in a GitHub issue.

Contributing

Bug reports, ideas and pull requests are welcome. CONTRIBUTING.md explains how to set up the repository, the commands, and how the packages are laid out.

License

MIT. Built on Formisch and Valibot.

About

Define Formisch forms in JSON, render them with your own components, or compile them to typed Valibot code.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages