All Projects → formsy → Formsy React

formsy / Formsy React

Licence: mit
A form input builder and validator for React JS

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Formsy React

svelte-form
JSON Schema form for Svelte v3
Stars: ✭ 47 (-93.36%)
Mutual labels:  validation, form, form-validation
Form Validation.js
The most customizable validation framework for JavaScript.
Stars: ✭ 127 (-82.06%)
Mutual labels:  validation, form-validation, form
Legit
input validation framework
Stars: ✭ 81 (-88.56%)
Mutual labels:  validation, form-validation, form
formalizer
React hooks based form validation made for humans.
Stars: ✭ 12 (-98.31%)
Mutual labels:  validation, form, form-validation
React Hook Form
📋 React Hooks for form state management and validation (Web + React Native)
Stars: ✭ 24,831 (+3407.2%)
Mutual labels:  validation, form-validation, form
Usetheform
React library for composing declarative forms, manage their state, handling their validation and much more.
Stars: ✭ 40 (-94.35%)
Mutual labels:  validation, form-validation, form
React Form With Constraints
Simple form validation for React
Stars: ✭ 117 (-83.47%)
Mutual labels:  validation, form-validation, form
Bootstrap Validate
A simple Form Validation Library for Bootstrap 3 and Bootstrap 4 not depending on jQuery.
Stars: ✭ 112 (-84.18%)
Mutual labels:  validation, form-validation, form
Approvejs
A simple JavaScript validation library that doesn't interfere
Stars: ✭ 336 (-52.54%)
Mutual labels:  validation, form-validation, form
Neoform
✅ React form state management and validation
Stars: ✭ 162 (-77.12%)
Mutual labels:  validation, form-validation, form
Ok
✔️ A tiny TypeScript library for form validation
Stars: ✭ 34 (-95.2%)
Mutual labels:  validation, form-validation, form
Resolvers
📋 Validation resolvers: Zod, Yup, Joi, Superstruct, and Vest.
Stars: ✭ 222 (-68.64%)
Mutual labels:  validation, form-validation, form
React Final Form
🏁 High performance subscription-based form state management for React
Stars: ✭ 6,781 (+857.77%)
Mutual labels:  validation, form-validation, form
Just Validate
Lightweight (~4,5kb gzip) form validation in Javascript Vanilla, without dependencies, with customizable rules (including remote validation), customizable messages and customizable submit form with ajax helper.
Stars: ✭ 74 (-89.55%)
Mutual labels:  validation, form-validation, form
Formhelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)
Stars: ✭ 155 (-78.11%)
Mutual labels:  validation, form-validation, form
Redux Form
A Higher Order Component using react-redux to keep form state in a Redux store
Stars: ✭ 12,597 (+1679.24%)
Mutual labels:  validation, form-validation, form
Bunny
BunnyJS - Lightweight native (vanilla) JavaScript (JS) and ECMAScript 6 (ES6) browser library, package of small stand-alone components without dependencies: FormData, upload, image preview, HTML5 validation, Autocomplete, Dropdown, Calendar, Datepicker, Ajax, Datatable, Pagination, URL, Template engine, Element positioning, smooth scrolling, routing, inversion of control and more. Simple syntax and architecture. Next generation jQuery and front-end framework. Documentation and examples available.
Stars: ✭ 473 (-33.19%)
Mutual labels:  validation, form-validation, form
datalize
Parameter, query, form data validation and filtering for NodeJS.
Stars: ✭ 55 (-92.23%)
Mutual labels:  validation, form
Vue Form
Form validation for Vue.js 2.2+
Stars: ✭ 618 (-12.71%)
Mutual labels:  validation, form-validation
pyvaru
Rule based data validation library for python 3.
Stars: ✭ 17 (-97.6%)
Mutual labels:  validation, form-validation

formsy-react

GitHub release CI Coverage Status GitHub contributors Typescript Types included

A form input builder and validator for React.

Quick Start API 1.x API

Background

christianalfoni wrote an article on forms and validation with React, Nailing that validation with React JS, the result of that was this library.

The main concept is that forms, inputs, and validation are done very differently across developers and projects. This React component aims to be that “sweet spot” between flexibility and reusability.

This project was originally located at christianalfoni/formsy-react if you're looking for old issues.

What You Can Do

  1. Build any kind of form element components. Not just traditional inputs, but anything you want, and get that validation for free
  2. Add validation rules and use them with simple syntax
  3. Use handlers for different states of your form. (onSubmit, onValid, etc.)
  4. Pass external errors to the form to invalidate elements (E.g. a response from a server)
  5. Dynamically add form elements to your form and they will register/unregister to the form

Install

yarn add formsy-react react react-dom and use with webpack, browserify, etc.

Formsy component packages

1.x to 2.x Upgrade Guide

The 2.0 release fixed a number of legacy decisions in the Formsy API, mostly a reliance on function props over value props passed down to wrapped components. However, the API changes are minor and listed below.

  • getErrorMessage() => errorMessage
  • getErrorMessages() => errorMessages
  • getValue() => value
  • hasValue() => hasValue
  • isFormDisabled(): => isFormDisabled
  • isFormSubmitted() => isFormSubmitted
  • isPristine() => isPristine
  • isRequired() => isRequired
  • isValid(): => isValid
  • showError() => showError
  • showRequired() => showRequired

Quick Start

1. Build a Formsy element

// MyInput.js
import { withFormsy } from 'formsy-react';
import React from 'react';

class MyInput extends React.Component {
  constructor(props) {
    super(props);
    this.changeValue = this.changeValue.bind(this);
  }

  changeValue(event) {
    // setValue() will set the value of the component, which in
    // turn will validate it and the rest of the form
    // Important: Don't skip this step. This pattern is required
    // for Formsy to work.
    this.props.setValue(event.currentTarget.value);
  }

  render() {
    // An error message is passed only if the component is invalid
    const errorMessage = this.props.errorMessage;

    return (
      <div>
        <input onChange={this.changeValue} type="text" value={this.props.value || ''} />
        <span>{errorMessage}</span>
      </div>
    );
  }
}

export default withFormsy(MyInput);

withFormsy is a Higher-Order Component that exposes additional props to MyInput. See the API documentation to view a complete list of the props.

2. Use your Formsy element

import Formsy from 'formsy-react';
import React from 'react';
import MyInput from './MyInput';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.disableButton = this.disableButton.bind(this);
    this.enableButton = this.enableButton.bind(this);
    this.state = { canSubmit: false };
  }

  disableButton() {
    this.setState({ canSubmit: false });
  }

  enableButton() {
    this.setState({ canSubmit: true });
  }

  submit(model) {
    fetch('http://example.com/', {
      method: 'post',
      body: JSON.stringify(model),
    });
  }

  render() {
    return (
      <Formsy onValidSubmit={this.submit} onValid={this.enableButton} onInvalid={this.disableButton}>
        <MyInput name="email" validations="isEmail" validationError="This is not a valid email" required />
        <button type="submit" disabled={!this.state.canSubmit}>
          Submit
        </button>
      </Formsy>
    );
  }
}

This code results in a form with a submit button that will run the submit method when the form is submitted with a valid email. The submit button is disabled as long as the input is empty (required) and the value is not an email (isEmail). On validation error it will show the message: "This is not a valid email".

3. More

See the API for more information.

Contribute

  • Fork repo
  • yarn
  • yarn lint runs lint checks
  • yarn test runs the tests
  • npm run deploy build and release formsy

Changelog

Check out our Changelog and releases

License

The MIT License (MIT)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].