🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

formal-react-forms

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formal-react-forms

The most sophisticated form state wrapper for React

0.0.5
Source
npm
Version published
Weekly downloads
3
-84.21%
Maintainers
1
Weekly downloads
 
Created
Source

Formal 🤵🏼

A very sophisticated form state manager for React. 🎩

Getting Started

Installing

npm i formal-react-forms

OR

yarn add formal-react-forms

Usage Example

Import

import Formal from "formal-react-forms";

Example Usage

<Formal
  isInitiallyValid={true}
  initialValues={{
    firstName: "",
    lastName: "",
    email: "",
    password: "",
    confirmPassword: "",
  }}
  validationSchema={[
    { field: "firstName", required: true },
    { field: "lastName", required: false },
    { field: "email", required: true },
    { field: "password", required: true },
    { field: "confirmPassword", required: true },
  ]}
  onSubmit={(
    actions: { setIsSubmitting: Function, setErrors: Function },
    values: {
      firstName: string,
      lastName: string,
      email: string,
      password: string,
      confirmPassword: string,
    }
  ) => onSubmit(actions, values)}
>
  {({
    isValid,
    errors,
    values,
    handleFormSubmit,
    onChangeValues,
    isSubmitting,
  }: any) => {
    return (
      <>
        <div>
          <input
            type="text"
            value={values.firstName}
            placeholder="First Name"
            onChange={({ target: { value } }) => {
              onChangeValues({ firstName: value });
            }}
          />
          {getError({ field: "firstName", errors })}
        </div>

        <div>
          <input
            type="text"
            value={values.lastName}
            placeholder="Last Name"
            onChange={({ target: { value } }) => {
              onChangeValues({ lastName: value });
            }}
          />
          {getError({ field: "lastName", errors })}
        </div>

        <div>
          <input
            type="email"
            value={values.email}
            placeholder="Email Address"
            onChange={({ target: { value } }) => {
              onChangeValues({ email: value });
            }}
          />
          {getError({ field: "email", errors })}
        </div>

        <div>
          <input
            type="password"
            placeholder="Password"
            value={values.password}
            onChange={({ target: { value } }) =>
              onChangeValues({ password: value })
            }
          />
          {getError({ field: "password", errors })}
        </div>

        <div>
          <input
            type="password"
            placeholder="Confirm Password"
            value={values.confirmPassword}
            onChange={({ target: { value } }) =>
              onChangeValues({ confirmPassword: value })
            }
          />
          {getError({ field: "confirmPassword", errors })}
        </div>

        <div>
          <button type="submit" onClick={handleFormSubmit} disabled={!isValid}>
            {isSubmitting ? "Loading..." : "Submit"}
          </button>
        </div>
      </>
    );
  }}
</Formal>

Authors

  • Brian Mullis - https://github.com/bmullis

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Keywords

react

FAQs

Package last updated on 24 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts