Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Willem-Jaap/formisch

 
 

Formisch

Formisch is a schema-based, headless form library for JS frameworks. It manages form state and validation. It is type-safe, fast by default and its bundle size is small due to its modular design. Try it out in our playground!

Highlights

  • Small bundle size starting at 2.5 kB
  • Schema-based validation with Valibot
  • Type safety with autocompletion in editor
  • It's fast – DOM updates are fine-grained
  • Minimal, readable and well thought out API
  • Supports all native HTML form fields

Example

I SolidJS a form starts with the createForm primitive. It initializes your form's store based on the provided Valibot schema and infers its types. Next, wrap your form in the <Form /> component. It's a thin layer around the native <form /> element that handles form validation and submission. Then, you can access the state of a field with the useField primitive or the <Field /> component to connect your inputs.

import { createForm, Field, Form } from '@formisch/solid';
import * as v from 'valibot';

const LoginSchema = v.object({
  email: v.pipe(v.string(), v.email()),
  password: v.pipe(v.string(), v.minLength(8)),
});

export default function LoginPage() {
  const loginForm = createForm({
    schema: LoginSchema,
  });

  return (
    <Form of={loginForm} onSubmit={(output) => console.log(output)}>
      <Field
        of={loginForm}
        path={['email']}
        render={(field) => (
          <div>
            <input {...field.props} value={field.input} type="email" />
            {field.errors && <div>{field.errors[0]}</div>}
          </div>
        )}
      />
      <Field
        of={loginForm}
        path={['password']}
        render={(field) => (
          <div>
            <input {...field.props} value={field.input} type="password" />
            {field.errors && <div>{field.errors[0]}</div>}
          </div>
        )}
      />
      <button type="submit">Login</button>
    </Form>
  );
}

In addition, Formisch offers several functions (we call them "methods") that can be used to manipulate the form state. These include focus, getErrors, getAllErrors, getInput, insert, move, remove, replace, reset, setErrors, setInput, submit, swap and validate. These methods allow you to control the form programmatically.

Feedback

Find a bug or have an idea how to improve the library? Please fill out an issue. Together we can make forms even better!

License

This project is available free of charge and licensed under the MIT license.

About

The modular and type-safe form library for any framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 94.5%
  • JavaScript 5.0%
  • CSS 0.5%