• Stars
    star
    217
  • Rank 182,446 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Functional reactive forms. Multi-layer validation, custom styling, field grouping, reactive props, and much more.

Package version Build status Vulnerabilities Dependencies status DevDepenencies status Greenkeeper badge

React Advanced Form

React Advanced Form

React Advanced Form is a library for tailoring real-world forms in React with pleasure and ease.


Features

Expectations shift

Trust and expect a form to do more than just rendering the fields. Our features are designed to handle cumbersome use cases with clean and performant code

Immutable

Each field interaction or update is a pure function that produces the next state of a field.

Composite fields

React Advanced Form is field-centric. That means you define flexible fields composites and reuse them throughout the application. Reflect even the most granular field state changes in the UI to achieve the outmost user experience.

import React from 'react'
import { createField, fieldPresets } from 'react-advanced-form'

const Input = ({ fieldState, fieldProps }) => {
  const { valid, invalid } = fieldState

  const classNames = [valid && 'has-success', invalid && 'has-error'].filter(
    Boolean,
  )

  return <input {...fieldProps} className={classNames.join(' ')} />
}

export default createField(fieldPresets.input)(Input)

Clean and fast

Develop production-ready forms in a speed of a prototype.

// This is not a diminished example, this is a finite form
<Form action={this.registerUser}>
  <Input name="username" required />
  <Input name="password" type="password" required />
</Form>

Layered validation schema

Select fields and declare validation rules using resolver functions. Utilize the order and priority of their execution to craft validation logic of any complexity.

export default {
  type: {
    password: {
      capitalLetter: ({ value }) => /[A-Z]/.test(value),
      oneNumber: ({ value }) => /[0-9]/.test(value),
    },
  },
  name: {
    confirmPassword: ({ get, value }) => {
      /**
       * The "confirmPassword" field will be re-validated whenever
       * the "value" prop of "userPassword" field updates.
       */
      return value === get(['userPassword', 'value'])
    },
  },
}

Each validation resolver can access respective field's value, fieldProps, and the form as the parameters. It can also reference other field's state via the get function, which creates a props subscription to re-evaluate the respective validation rule in real time.

Say goodbye to crowded validate functions, welcome clean validation schema!

Reactive props

How much effort would it take you to make one field required based on another field(s)? Yes, the correct answer is—one line of code:

<Input
  name="firstName"
  required={({ get }) => !!get(['lastName', 'value'])} />
<Input
  name="lastName"
  required={({ get }) => !!get(['firstName', 'value'])} />

Get as many data from the sibling fields as needed, and build your logic around that. Rely on reactive programming that will re-evaluate a resolver function whenever the referenced field props update.

Field grouping

Control the serialized data structure on the layout level by grouping the fields. Take advantage of nested and split groups.

<Input name="companyName" value="Google" />

<Field.Group name="billingAddress">
  <Input name="firstName" value="John" />
  <Input name="lastName" value="Maverick" />
</Field.Group>

<Checkbox name="termsAndConditions" checked />

<Field.Group name="deliveryAddress">
  <Input name="firstName" value="Catheline" />
  <Input name="lastName" value="McCoy" />
</Field.Group>

The form above serializes into the following JSON:

{
  "companyName": "Google",
  "billingAddress": {
    "firstName": "John",
    "lastName": "Maverick"
  },
  "termsAndConditions": true,
  "deliveryAddress": {
    "firstName": "Catheline",
    "lastName": "McCoy"
  }
}

Third-party integration

React Advanced Form can be used with any third-party fields library by using powerful createField API. It also allows to create custom fields from literally any component.


Getting started

Install

npm install react-advanced-form --save

Make sure to have React (15.0+) installed in your project.

Guidelines

Starting with something new may appear challenging. We have prepared step-by-step instructions on how to Get started with React Advanced Form to make the adoption process clear and fast.


Materials


Browser support

Chrome Firefox Safari iOS Safari Edge Internet Explorer
65+ 57+ 9+ 8+ 41+ 11*

* There is no official support for Internet Explorer. Consider educating the web and deprecating legacy browsers.


Live examples


Contributing

Any of your contributions are highly appreciated. Please read through the Contribution guidelines beforehand. Development isn't the only way to support, there are many more.

More Repositories

1

naming-cheatsheet

Comprehensive language-agnostic guidelines on variables naming. Home of the A/HC/LC pattern.
13,893
star
2

atomic-layout

Build declarative, responsive layouts in React using CSS Grid.
TypeScript
1,129
star
3

vscode-nako-theme

Nako is a premium dark color theme for Visual Studio Code.
Shell
61
star
4

page-with

A library for usage example-driven in-browser testing of your code.
TypeScript
59
star
5

kettanaito.com

@kettanaito's personal blog.
MDX
55
star
6

remix-og-image

Build-time in-browser Open Graph image generation for Remix.
TypeScript
27
star
7

rettime

Type-safe dependency-free EventTarget-inspired event emitter for browser and Node.js.
TypeScript
25
star
8

msw-with-remix

Minimal example of using Mock Service Worker with Remix. Both server- and client-side.
JavaScript
23
star
9

create-typescript-library

A template repository for a superb library written in TypeScript (ESM/UMD/CJS, tree-shaking, CI).
TypeScript
19
star
10

movie-app

Movie App for the "Mocking REST and GraphQL APIs with MSW" course on Egghead.
TypeScript
19
star
11

zed-theme-evil-rabbit

An Evil Rabbit theme for Zed.
19
star
12

atomic-layout-docs

Documentation website for Atomic layout library.
JavaScript
18
star
13

react-data-preview

Fancy interactive preview of your JavaScript data.
JavaScript
17
star
14

graphql-server

Production-ready setup of GraphQL Express server based on Apollo Server.
JavaScript
15
star
15

protocol-handlers

Utilities to work with protocol handlers (like "vscode://") on the web.
TypeScript
13
star
16

react-advanced-form-addons

Form prototyping framework for React Advanced Form. Tailor production-ready forms in a matter of minutes. Write the logic, do the styles later.
JavaScript
12
star
17

until-connected

Wait for a connection at the given target without making any requests.
TypeScript
12
star
18

fs-teardown

Teardown API for testing file system-dependent code.
TypeScript
11
star
19

turborepo-remix-prisma

Turborepo with a Remix app and Prisma.
TypeScript
11
star
20

next-testing-library

Utilities for testing NextJS applications.
TypeScript
8
star
21

jest-custom-matchers

Source code for the "Practical Guide To Custom Jest Matchers" article.
TypeScript
8
star
22

webpack-http-server

On-demand runtime webpack compilations over HTTP.
TypeScript
6
star
23

service-worker

W3C specification-compliant implementation of Service Workers for Node.js.
TypeScript
6
star
24

test-flat

A test framework extension to support resources teardown and cleanup in flat tests.
TypeScript
6
star
25

react-advanced-form-docs

Documentation for React Advanced Form.
5
star
26

redux-dynamics

Strongly-typed collection of tools to make your Redux workflow more dynamic.
JavaScript
4
star
27

rsc-frameworkless

A frameworkless, barebones example of RSC usage.
JavaScript
4
star
28

kentcdodds-worker-redirect

JavaScript
3
star
29

readable-stream-polyfill

"ReadableStream" polyfill based on the eponymous implementation from Node.js.
TypeScript
3
star
30

namespace-station

Comprehensive function names suggestions based on language analyzis. Say what your function should do, get a function name back.
JavaScript
3
star
31

graphql-mongo

Utilities for faster GraphQL + MongoDB integration.
JavaScript
3
star
32

sentinel-dom

Dependency-free VanillaJS way to determine the visibility of DOM elements.
TypeScript
3
star
33

events-pool

Accumulate multiple events, and their data, from different sources into a single pool.
JavaScript
3
star
34

graphql-query-shortlink

Express middleware for creating GraphQL query shortlinks to GraphiQL.
TypeScript
2
star
35

service-worker-multiple

Example of registering multiple Service Workers on a single scope.
JavaScript
1
star
36

url-to-string-issue

JavaScript
1
star
37

tbg

Turn-based dice game just for fun.
TypeScript
1
star
38

create-prop-types

A utility function to create custom prop type validators for React with ".isRequired" chaining built in.
JavaScript
1
star
39

atomic-layout-docs-legacy

GitBook documentation for Atomic layout library.
1
star
40

msw-axios-happy-dom

JavaScript
1
star
41

tug-o-war

A tug-o-war game with Remix, WebSockets, and MSW.
TypeScript
1
star
42

whatwg-fetch-json

JavaScript
1
star
43

project-template-remix

Remix template for CodeSandbox Projects
TypeScript
1
star
44

cra-box

JavaScript
1
star
45

service-worker-readable-stream

Respond to "fetch" event with a ReadableStream.
JavaScript
1
star
46

jest-es6

Example repository with unit testing an ES6 code with Jest.
JavaScript
1
star
47

webpack-file-router-plugin

Webpack plugin that derives a JSON manifest from a directory to enable file system-based routing.
TypeScript
1
star