All Projects → JoshuaAmaju → elderform

JoshuaAmaju / elderform

Licence: MIT license
💪🏽 Form creation made easy, backed by state machines

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to elderform

Formik
Build forms in React, without the tears 😭
Stars: ✭ 29,047 (+96723.33%)
Mutual labels:  form, formik
dynamic-form-json
dynamic-form-json is a tiny library to generate a Form in React automatically based on certain array of object that passed as a props
Stars: ✭ 16 (-46.67%)
Mutual labels:  form, formik
Kirby Uniform
A versatile Kirby plugin to handle web form actions.
Stars: ✭ 214 (+613.33%)
Mutual labels:  form
react-plough
A library to help tend your react form fields
Stars: ✭ 31 (+3.33%)
Mutual labels:  form
Htmlpurifierbundle
HTML Purifier is a standards-compliant HTML filter library written in PHP.
Stars: ✭ 234 (+680%)
Mutual labels:  form
Vue Dynamic Form Component
Vue dynamic nested form component, support nested Object/Hashmap/Array. Vue动态多级表单组件,支持嵌套对象/Hashmap/数组。
Stars: ✭ 220 (+633.33%)
Mutual labels:  form
Fui
Add CLI & form interface to your program. Docs: https://docs.rs/fui
Stars: ✭ 244 (+713.33%)
Mutual labels:  form
Heyui
🎉UI Toolkit for Web, Vue2.0 http://www.heyui.top
Stars: ✭ 2,373 (+7810%)
Mutual labels:  form
WP-Media-Uploader
Easily create a custom media upload button in WordPress admin dashboard that you can use in your plugin
Stars: ✭ 25 (-16.67%)
Mutual labels:  form
Jh flutter demo
a flutter demo
Stars: ✭ 229 (+663.33%)
Mutual labels:  form
Vue Form Json Schema
Create forms using JSON schema. Bring your components!
Stars: ✭ 253 (+743.33%)
Mutual labels:  form
React Hooks Helper
A custom React Hooks library that gives you custom hooks for your code.
Stars: ✭ 227 (+656.67%)
Mutual labels:  form
Simple React Form
The simplest way to handle forms in React
Stars: ✭ 224 (+646.67%)
Mutual labels:  form
Django Bootstrap Modal Forms
A Django plugin for creating AJAX driven forms in Bootstrap modal.
Stars: ✭ 244 (+713.33%)
Mutual labels:  form
Angular Surveys
Angular survey / form builder inspired by Google Forms
Stars: ✭ 219 (+630%)
Mutual labels:  form
ndaify-web
NDAify helps you keep your trade secrets under wraps 🔒
Stars: ✭ 33 (+10%)
Mutual labels:  formik
Ant Plus
🔺 Ant Design 表单简化版
Stars: ✭ 212 (+606.67%)
Mutual labels:  form
Learn To Send Email Via Google Script Html No Server
📧 An Example of using an HTML form (e.g: "Contact Us" on a website) to send Email without a Backend Server (using a Google Script) perfect for static websites that need to collect data.
Stars: ✭ 2,718 (+8960%)
Mutual labels:  form
Form bloc
🔥 Dart and Flutter Package 🔥 Easy Form State Management using BLoC pattern 🔥 Wizard/stepper forms, asynchronous validation, dynamic and conditional fields, submission progress, serialization and more! 🔥
Stars: ✭ 239 (+696.67%)
Mutual labels:  form
storybook-xstate-addon
A storybook addon to assist with writing stories that rely on xstate
Stars: ✭ 48 (+60%)
Mutual labels:  xstate

Elderform

Form handling without tears and predictable form state based on defined parameters. Elderform gives you everything you need to create robust forms and stays out of your way.

npm bundle size npm npm

Features

  • Async validation
  • Create reusable forms
  • Predictable form state
  • Cancel form submission
  • Full typescript support
  • Schemaless (define your fields as you like)
  • Tiny: fully packed in just ~6kb
  • Use any validation library or roll your own
  • Framework agnostic
  • Ships with sensible defaults for form handling
  • No more "how do I prevent multple submission while currently submitting"

Quick start

pnpm add xstate elderform
import * as z from 'zod';
import {createForm} from 'elderform';

const form = createForm({
  initialValues: {
    age: 10,
    name: {
      last: '',
      first: '',
      middle: '',
    },
    mother: {
      name: {
        last: '',
        first: '',
        middle: '',
      },
    },
  },
  onSubmit: () => {
    return Promise.resolve();
  },
});

form.spawn('name', null, v => zod.string().parse(v))

form.subscribe((state) => {
  ...
});

form.submit();

API

createForm(config)

  • config (object) - config object from creating the form state machine (see below)

Config:

  • initialValues? (object) - initial form values
  • onSubmit(values: object) - an async function that handles form submission

Returns:

An object which provides

  • submit ((...ignore?: string[]) => void) - a function to submit the form
  • reset - a function to reset the form state to its initial state
  • cancel (() => void) - function to cancel either the form validation or the current form submission
  • submitAsync - async version of submit and resolves with the submission result
  • set - ((name, value) => void) - a function to set the value for any given field
  • subscribe ((stateListener) => () => void) - a state listener with the current state of the form (see below for stateListener)
  • __service - the base service (xstate interpreter), made available for library authors to creating wrappers for frameworks
  • validate ((field, value?) => void) - function to validate given field
  • spawn ((name, value, validator) => void) - An escape hatch to spawn new fields not specified in the schema. (useful for creating dynamic forms)
  • kill ((name) => void) - A function to kill a spawned field

State Listener

subscribe(currentState)

currentState

  • state - Form State

  • Boolean flags derived from form state value

    • isIdle
    • isValidating
    • isSubmitting
    • submitted
    • isError
    • isSuccess - similar to submitted
  • Others

    • values (object) - form values (Defaults to an empty object)
    • data (TData | null)
      • Defaults to undefined
      • The last data returned from successfully submission
    • error (TError | null)
      • Defaults to undefined
      • The error object last from submission, if an error was thrown
    • errors (Record<string, TErrors>) - an object of errors for each field after validation
    • dataUpdatedAt (number) - The timestamp for when the form most recently submitted successfully and returned data (Defaults to 0)
    • errorUpdatedAt (number) - The timestamp for when the form most recently failed to submit successfully and returned error (Defaults to 0).

Form State

  • idle - when the form isn't actively performing any operation
  • validating - when the defined schema is being validated
  • submitting - when the is being submitted
  • submitted - if the form submitted successfully without any error
  • error - if the submission attempt resulted in an error. The error is contained in the corresponding error property

Field State

  • idle - when the field is not performing any action
  • validating - when the field is validating
  • success - if the field was validated successfully
  • failed - if the field failed validation

Examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].