README.md

🏁 React Final Form HTML5 Validation

🏁 React Final Form HTML5 Validation is swappable replacement for 🏁 React Final Form's Field component that provides two-way HTML5 Validation bindings. The bindings are two-way because any HTML5 contraint validation errors will be added to the 🏁 Final Form state, and any field-level validation errors from 🏁 Final Form will be set into the HTML5 validity.customError state. Unfortunately, this functionality is not compatible with 🏁 React Final Form record-level validation, so the two should not be mixed.

Why not add this functionality directly into the officially bundled Field component?

Good question. The reason is that not everyone needs this functionality, and not everyone is using 🏁 React Final Form with the DOM (e.g. some people use it with React Native). Therefore it makes sense to make this a separate package. This version of Field is a thin wrapper over the official Field component, and the only Field API that this library uses/overrides is the field-level validate prop, so even if you are using this library's Field component, you will still get improvements as features are added to the 🏁 React Final Form library in the future.

Safari

Chrome

Firefox

Installation

Usage

The way you specify rules and error messages in HTML5 is by giving first a rule prop, e.g. required, min, maxLength, and then an error message prop, e.g. valueMissing, rangeUnderflow, or tooLong, respectively. This library comes with built-in English defaults for the error messages, but you will probably want to override those by passing in your own.