Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

formalizer

nosachamos200MIT2.9.0TypeScript support: included

React hooks based form validation made for humans.

form validation, form, validation, react, hooks, awesome, usable

readme

Build Status codecov

styled with prettier npm Snyk Vulnerabilities for GitHub Repo GitHub

Formalizer is a React Hooks based form validation library made for humans. The cleanest code or your money back ;)

Formalizer

Simple, tiny, extensible, intuitive, documented, fully tested, magical.


Installation

yarn add formalizer

or

npm install formalizer --save

Sample Usage

import { useFormalizer } from 'formalizer';

const UserProfileComponent = () => {
  const { formRef, useInput, errors, isValid } = useFormalizer();

  return (
    <form ref={formRef}>
      <input {...useInput('name', ['isRequired'])} />
      <span>{errors['name']}</span>

      <input {...useInput('email', ['isRequired', 'isEmail'])} />
      <span>{errors['email']}</span>

      <button disabled={!isValid} type="submit">
        Submit
      </button>
    </form>
  );
};

For a complete guide on how each of these pieces work, see our tutorial.

In a Nutshell

Use the useFormalizer hook to gain access to the useInput hook, the errors currently in your form, whether the form is valid or not and more.

Then, use the useInput to setup validations on your form inputs.

Formalizer offers two built in validators out-of-the-box and it integrates with the awesome validator library seamlessly, which means if you install it you can use all of their validators.

But know that writing your own custom validators is super easy.

Also, you may create global validators so that they accessible throughout your app. Doing so helps keep your code DRY and facilitates maintaining it.

Finally, if you use Material UI you may like the fact Formalizer integrates with it. If you use some other UI framework, chances are you can tweak our settings to make it work with it.

Contributing

Contributions are very welcome!

We follow the "fork-and-pull" Git workflow.

  1. Create a Fork and clone it

    Simply click on the “fork” button of the repository page on GitHub.

    The standard clone command creates a local git repository from your remote fork on GitHub.

  2. Modify the Code

    In your local clone, modify the code and commit them to your local clone using the git commit command.

    Run yarn test and make sure all tests still pass.

    Run tslint --project . and make sure you get no warnings.

  3. Push your Changes

    Make sure to update affected tests and/or add tests to any new features you may have created.

    We are very careful to make sure coverage does not drop.

  4. Create a Pull Request

    We will review your changes and possibly start a discussion.

    If changes are required, you can simply push these changes into your fork by repeating steps #3 and #4 and the pull request is updated automatically.

License

MIT


Created and maintained by Eduardo Born with ❤ and coffee

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

v2.9.0

31 December 2022

v2.8.0

31 December 2022

v2.7.0

31 December 2022

  • chore(deps): bump eventsource from 1.0.7 to 1.1.1 #5
  • chore(deps-dev): bump codecov from 3.5.0 to 3.8.3 #6
  • chore(deps-dev): bump codecov from 3.5.0 to 3.8.3 f733928
  • Allow a custom error message to be returned by the validator function. d82bee2
  • chore(deps): bump eventsource from 1.0.7 to 1.1.1 61d4574

v2.6.0

13 March 2022

v2.5.0

13 March 2022

  • chore(deps): bump url-parse from 1.4.7 to 1.5.10 #4
  • Adding option to keep unknown form attributes in the result data ddfcc80
  • 2.5.0 b04e9e8

v2.4.2

26 February 2022

  • Fixing a bug on the submit handler data filtering code 423691c
  • Filtering values before they are passed to the form submit handler so that unknown properties are excluded. e70449e
  • 2.4.2 b552312

v2.4.1

26 February 2022

v2.4.0

26 February 2022

  • Submit handler should only receive data from inputs declared in the form. Unknown properties that may have come with initial values should be filtered out. 502f56d
  • 2.4.0 7e86463

v2.3.0

20 February 2022

v2.2.0

20 February 2022

  • Fixing tests now that initial values are no longer required for form data to show in the results e35f202
  • Allowing initial values to be undefined, and assuming reasonable defaults in that case so that users dont have to provide dummy initial values 8d464a7
  • Update third-party-validators.md a7e689e

v2.1.12

19 February 2022

v2.1.11

19 February 2022

v2.1.10

18 February 2022

v2.1.9

18 February 2022

v2.1.8

18 February 2022

v2.1.7

18 February 2022

  • 2.1.7 1be1103
  • Updating typedoc doc generation command now that we upgraded to version 0.22.11 7b5867b

v2.1.6

18 February 2022

v2.1.5

18 February 2022

v2.1.4

18 February 2022

  • chore(deps-dev): bump standard-version from 4.4.0 to 8.0.1 #2
  • chore(deps-dev): bump standard-version from 4.4.0 to 8.0.1 0e38d78
  • Giving useFormalizer return a named type so that users can more easily pass the entire object into children components if the form is broken into multiple components 47791f6
  • Update README.md d7088cc

v2.1.3

16 September 2019

  • Fixing bug where, upon change, we erroneously tried to get the value of an input using the 'currentTarget' property instead of 'target'. caa55d5
  • 2.1.3 005bb6f

v2.1.2

5 September 2019

  • Bringing back tests we commented out to speed up testing bug fix 99ca0b0
  • If no form is connected, the submitHandler not invoked until all data is valid. 630ab03
  • 2.1.2 3cd3318

v2.1.1

5 September 2019

  • 2.1.1 fe56249
  • If settings are given to the useFormalizer hook, they should be merged with the global FormalizerSettings instead of entirely replacing them. 5bc672e

v2.1.0

5 September 2019

  • Small typing fixes for validator config options 54dd211
  • 2.1.0 2c33917

v2.0.1

18 August 2019

  • Attempting to fix typings so that useInput hooks can be used with Material UI on a TypeScript enabled env without warnings. 0dd4091
  • 2.0.1 1bef2e7
  • Switching to interface instead of type literal so that linter will be happier :) 13b7157

v2.0.0

17 August 2019

  • Removing option to provide validations to toggle inputs, checkboxes and radio buttons - there doesnt seem to be a use case for this. 8428494
  • 2.0.0 c1e0bac
  • Small fix to the documentation d02410c

v1.1.0

12 August 2019

  • Fixing typings for input event handlers, adding validation setting to allow for useInput hooks to omit the type attribute and created associated tests for this feature 6b30812
  • 1.1.0 ac695cd
  • Small documentation update 57823f2

v1.0.12

12 August 2019

  • Typing fix for input hook's type attribute dc73abe
  • Small changes to allow the useToggleInput to add no type attribute to the target element 9d67768
  • 1.0.12 5356675

v1.0.11

12 August 2019

  • Fix for removing errors from input when multiple errors are being reported and some (but not all) of the errors no longer apply due to a change in the input value 24382a6
  • 1.0.11 b282d5d

v1.0.10

12 August 2019

  • Fixing typings for useInput validation parameter edf73d9
  • 1.0.10 86eaa2c

v1.0.9

12 August 2019

  • A few more typing corrections 77d097e
  • Typing correction for onKeyPress input event handler b76a4cd
  • 1.0.9 574d4f4

v1.0.8

12 August 2019

v1.0.7

12 August 2019

v1.0.6

12 August 2019

v1.0.5

12 August 2019

  • Making sure our release commit does not show in the changelog 5d3b087
  • 1.0.5 22d0dd6

v1.0.4

12 August 2019

  • Adjusting release so that changelog includes changes in the current version 0380c00
  • 1.0.4 4ea5095

v1.0.3

12 August 2019

  • Updates to release scripts and formatting with wider print width 641f387
  • 1.0.3 7f071f2

v1.0.2

12 August 2019

  • Small fix to package.json scripts 67a8c92
  • Changing npm scripts to support multiple types of release (patch, minor, major) e3324cd
  • 1.0.2 0bfb725

v1.0.1-0

12 August 2019

  • Adding support for all errors associated with a given input to be reported at once, instead of always only the first found error only bc758a6
  • Adding tests and documentation for reporting multiple errors at once 601d1e9
  • 1.0.1-0 d8878e8

v1.0.0-rc.19

8 August 2019

  • 1.0.0-rc.19 7950080
  • Attempting to solve dev dependencies issue missing on travis build 967fda1
  • Adding jest to the set of global installs on our travis.yml ab82371

v1.0.0-rc.18

6 August 2019

v1.0.0-rc.17

5 August 2019

  • Fixing typings so that submit handler function arguments' types will be correctly inferred f7131b7
  • 1.0.0-rc.17 968e5b8
  • Doc generation doesn't support spread operator being used on something other than an object type 94fcc63

v1.0.0-rc.16

22 July 2019

  • 1.0.0-rc.16 c950ac1
  • Small fix to prevent duplicated invocations of form submit handler e3f434d

v1.0.0-rc.15

22 July 2019

  • Do not invoke submit handler if form data hasn't changed. 3eb43a6
  • Small documentation corrections 7c84fda
  • 1.0.0-rc.15 f17a13f

v1.0.0-rc.14

22 July 2019

v1.0.0-rc.13

22 July 2019

  • Adding documentation for the new useCheckboxInput and useRadioInput hooks, as well as adding them to our tutorial. d3be32b
  • 1.0.0-rc.13 20144e9
  • Testing prettier test file formatting f30c839

v1.0.0-rc.12

21 July 2019

  • Renaming internal validations input function again so that it avoids warning message from react about unknown event handlers - cant use cammel case, or we get another warning cbbb9e5
  • 1.0.0-rc.12 2f35e70

v1.0.0-rc.11

21 July 2019

  • Renaming internal onRunValidators input function so that it avoids warning message from react about unknown event handlers 8d0752e
  • 1.0.0-rc.11 2bbd40e

v1.0.0-rc.10

20 July 2019

v1.0.0-rc.9

20 July 2019

  • Fixing bug where checkboxes didn't come out checked when their initial value was set to true. Added to test to cover this scenario. eaf52eb
  • 1.0.0-rc.9 fbb0fa5

v1.0.0-rc.8

20 July 2019

  • Breaking files apart for easier maintanance, breaking up tests as well, adding a few new tests to increase coverage. 53af568
  • 1.0.0-rc.8 ad9805f

v1.0.0-rc.7

19 July 2019

  • Breaking source into different files in preparation for our version 1.0.0 b669e56
  • Switching back to interfaces instead of type literals where possible 5151611
  • 1.0.0-rc.7 a93987f

v1.0.0-rc.6

19 July 2019

  • Adding support for saving/handling data changes on disconnected forms, fixing issue related to checkboxes triggering submit handler multiple times upon toggle, updating documentation. 49d612e
  • 1.0.0-rc.6 778bccc

v1.0.0-rc.5

13 July 2019

  • Adding tests for dynamic error messages, fixing some tests c0c39ed
  • Adding documentation to dynamic error messages support 1ce747c
  • 1.0.0-rc.5 14d828d

v1.0.0-rc.4

13 July 2019

  • Adding support for dynamic error messages generated by a function fc2167e
  • Fixing peer and optional dependency versions a96f153
  • 1.0.0-rc.4 5fd947a

v1.0.0-rc.3

13 July 2019

  • 1.0.0-rc.3 211d8e8
  • Updating peer and optional dependencies minimum versions 122e7eb

v1.0.0-rc.2

11 July 2019

v1.0.0-rc.1

11 July 2019

v1.0.0-beta.12

11 July 2019

  • Switching parameter order for the useFormalizer hook for increased simplicity abd66cc
  • 1.0.0-beta.12 ad8ef7f

v1.0.0-beta.11

10 July 2019

  • Adding validations for invalid useFormalizer hook arguments, allowing for null arguments c4e9e76
  • 1.0.0-beta.11 8822347

v1.0.0-beta.10

9 July 2019

  • Setting webpack's libraryTarget to umd d1bc4fb
  • 1.0.0-beta.10 89947fc

v1.0.0-beta.9

9 July 2019

v1.0.0-beta.8

9 July 2019

  • Fixing react external setting in webpack 1f3e5d7
  • 1.0.0-beta.8 ad9dcbb

v1.0.0-beta.7

9 July 2019

v1.0.0-beta.6

9 July 2019

  • SImplifying the API by making the useFormalizer hook return a formRef instead of requiring one as an argument. 52122b4
  • Create CODE_OF_CONDUCT.md 6fb3662
  • Create CONTRIBUTING.md bffdd24

v1.0.0-beta.5

8 July 2019

v1.0.0-beta.4

8 July 2019

  • Simplifying syntax for custom validators, updating documentatation, updating tests to match new syntax de7b17c
  • Documentation updates 3cb7beb
  • Groupng formalizer settings into an object passed into the useFormalizer hook, adding documentation for it, renaming global settings object to FormalizerSettings 94d635f

v1.0.0-beta.3

5 July 2019

  • Adding docsify documentation to the project 3a40df2
  • Adding more documentation 2fc6576
  • Renaming 'ValidatorDefaults' to 'GlobalValidators' as this better reflects what it does - hosts validators that can then be used from anywhere in your app 9a88f4c

v1.0.0-beta.2

4 July 2019

  • Adding built in mustMatch validator, passing form data to validators, adding tons of README documentation, Simplifying test's markup 2571bec
  • Adding tests to ensure formData is provided to validators, fixing a couple of minor bugs a66dcde
  • Small fixes to README 31e2e94

v1.0.0-beta.1

4 July 2019

  • Making sure validator lib is not included in our bundle since it is an optional dependency 5ea6524
  • 1.0.0-beta.1 d47458f

v1.0.0-alpha.8

3 July 2019

  • 1.0.0-alpha.8 55faeda
  • Adding protection against a few more invalid configurations, more tests d53c3c8

v1.0.0-alpha.7

1 July 2019

  • Making 'validator' an optional dependency and adding associated tests a77bef4
  • 1.0.0-alpha.7 f47e089

v1.0.0-alpha.6

30 June 2019

v1.0.0-alpha.5

30 June 2019

v1.0.0-alpha.4

30 June 2019

  • Update README.md #1
  • Removing exclusion pattern and checking if this resolves issue of coverage unknown in travis d66511e
  • feat(core): adding tests for everything and fixing all the known bugs 4872761
  • test: adding test coverage to travis run, sending coverage details to coverall, adding readme coverage badge 4d19f51

v1.0.0-alpha.3

26 June 2019

  • refactor(core): hanging gloal validation settings to a more user-friendly name fd984c3
  • 1.0.0-alpha.3 432266d

v1.0.0-alpha.2

25 June 2019

  • chore(build): reducing the prettier line width, rebuilding without react set as a webpack global fbf27ff
  • 1.0.0-alpha.2 8d5f79e

v1.0.0-alpha.1

25 June 2019

  • feat(core): formalizer v1 alpha 0 complete, first test in and working. Sources coverted to typescript. Build working efde698
  • chore(index): removing cache files from index 0343db2
  • Initial commit 560a39d