diff --git a/README.md b/README.md index 2484812b..a9f5b5f1 100644 --- a/README.md +++ b/README.md @@ -2,26 +2,29 @@ Conform is a form validation library built on top of the [Constraint Validation](https://caniuse.com/constraint-validation) API. -- **Progressive Enhancement**: It is designed based on the [HTML specification](https://html.spec.whatwg.org/dev/form-control-infrastructure.html#the-constraint-validation-api). From validating the form to reporting error messages for each field, if you don't like part of the solution, just replace it with your own. -- **Framework Agnostic**: The DOM is the only dependency. Conform makes use of native [Web APIs](https://developer.mozilla.org/en-US/docs/Web/API) exclusively. You don't have to use React / Vue / Svelte to utilise this library. -- **Flexible Setup**: It can validates fields anywhere in the dom with the help of [form attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#form). Also enables CSS pseudo-classes like `:valid` and `:invalid`, allowing flexible styling across your form without the need to manipulate the class names. +- **Progressive Enhancement**: Its APIs are designed with progressive enhancement in mind to ensure a smooth and resillent experience before javascript is ready. +- **Server-first validation**: It simplifies the mental model by utilizing a server-first validation flow which submits your form for validation. +- **Lightweight**: It is only [4kB](https://bundlephobia.com/package/@conform-to/react) compressed thanks to all the native [Web APIs](https://developer.mozilla.org/en-US/docs/Web/API). _#useThePlatform_ ## Quick start - + ```tsx import { useForm, useFieldset } from '@conform-to/react'; export default function LoginForm() { const form = useForm({ - onSubmit(event, { submission }) { + onSubmit(event) { event.preventDefault(); - console.log(submission); + const formData = new FormData(event.currentTarget); + const value = Object.fromEntries(formData); + + console.log(value); }, }); - const { email, password } = useFieldset(form.ref); + const { email, password } = useFieldset(form.ref, form.config); return (
@@ -41,16 +44,6 @@ export default function LoginForm() { } ``` -Learn more about conform [here](https://conform.guide/basics) +Learn more about conform [here](https://conform.guide/basics). - -## API References - - -| Package | Description | Size | -| :------ | :---------- | :--- | -| [@conform-to/react](packages/conform-react) | View adapter for [react](https://github.com/facebook/react) | [![package size](https://img.shields.io/bundlephobia/minzip/@conform-to/react)](https://bundlephobia.com/package/@conform-to/react) | -| [@conform-to/yup](packages/conform-yup) | Schema resolver for [yup](https://github.com/jquense/yup) | [![package size](https://img.shields.io/bundlephobia/minzip/@conform-to/yup)](https://bundlephobia.com/package/@conform-to/yup) | -| [@conform-to/zod](packages/conform-zod) | Schema resolver for [zod](https://github.com/colinhacks/zod) | [![package size](https://img.shields.io/bundlephobia/minzip/@conform-to/zod)](https://bundlephobia.com/package/@conform-to/zod) | - diff --git a/docs/basics.md b/docs/basics.md index cd47a183..88eb1911 100644 --- a/docs/basics.md +++ b/docs/basics.md @@ -1,6 +1,6 @@ # Basics -In this section, we will cover how to build a simple login form by utilizing native constraint and then enhancing it with conform. +In this section, we will show you how to build a login form by utilizing the **Constraint Validation** API with **Conform**. @@ -8,8 +8,9 @@ In this section, we will cover how to build a simple login form by utilizing nat - [Installation](#installation) - [Quick start](#quick-start) +- [Constraint Validation](#constraint-validation) - [Capturing errors](#capturing-errors) -- [Styling input](#styling-input) +- [Customize messages](#customize-messages) - [Early reporting](#early-reporting) - [Demo](#demo) @@ -25,7 +26,7 @@ npm install @conform-to/react To begin, let's make a login form with 2 basic requirements: -- The **email** field should be a valid email address +- The **email** field should contain a valid email address - The **password** field should not be empty ```tsx @@ -36,7 +37,8 @@ export default function LoginForm() { event.preventDefault(); const formData = new FormData(event.currentTarget); - console.log(formData); + + console.log(Object.fromEntries(formData)); }} >