All Projects → foxhound87 → Mobx React Form

foxhound87 / Mobx React Form

Licence: mit
Reactive MobX Form State Management

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mobx React Form

Mobx Rest
REST conventions for Mobx
Stars: ✭ 164 (-84.09%)
Mutual labels:  reactive, state, mobx
Formily
Alibaba Group Unified Form Solution -- Support React/ReactNative/Vue2/Vue3
Stars: ✭ 6,554 (+535.69%)
Mutual labels:  reactive, form, mobx
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 (-54.12%)
Mutual labels:  validation, form
Validator.js
⁉️轻量级的 JavaScript 表单验证,字符串验证。没有依赖,支持 UMD ,~3kb。
Stars: ✭ 486 (-52.86%)
Mutual labels:  validation, form
Inferno Most Fp Demo
A demo for the ReactJS Tampa Bay meetup showing how to build a React+Redux-like architecture from scratch using Inferno, Most.js, reactive programmning, and various functional programming tools & techniques
Stars: ✭ 45 (-95.64%)
Mutual labels:  reactive, observables
Usetheform
React library for composing declarative forms, manage their state, handling their validation and much more.
Stars: ✭ 40 (-96.12%)
Mutual labels:  validation, form
React Hook Form
📋 React Hooks for form state management and validation (Web + React Native)
Stars: ✭ 24,831 (+2308.44%)
Mutual labels:  validation, form
Vvalidator
🤖 An easy to use form validator for Kotlin & Android.
Stars: ✭ 592 (-42.58%)
Mutual labels:  validation, form
Awesome Rxjs
A collection of awesome RxJS resources
Stars: ✭ 314 (-69.54%)
Mutual labels:  reactive, observables
React Final Form
🏁 High performance subscription-based form state management for React
Stars: ✭ 6,781 (+557.71%)
Mutual labels:  validation, form
Form Backend Validation
An easy way to validate forms using back end logic
Stars: ✭ 784 (-23.96%)
Mutual labels:  validation, form
Swiftyform
iOS framework for creating forms
Stars: ✭ 907 (-12.03%)
Mutual labels:  validation, form
Formstate
❤️ Form state so simple that you will fall in love 🌹
Stars: ✭ 357 (-65.37%)
Mutual labels:  form, mobx
Ngx Errors
A declarative validation errors module for reactive forms.
Stars: ✭ 472 (-54.22%)
Mutual labels:  reactive, validation
Approvejs
A simple JavaScript validation library that doesn't interfere
Stars: ✭ 336 (-67.41%)
Mutual labels:  validation, form
Reatom
State manager with a focus of all needs
Stars: ✭ 567 (-45%)
Mutual labels:  reactive, state
Ok
✔️ A tiny TypeScript library for form validation
Stars: ✭ 34 (-96.7%)
Mutual labels:  validation, form
Effector
The state manager ☄️
Stars: ✭ 3,572 (+246.46%)
Mutual labels:  reactive, state
Validate
A simple jQuery plugin to validate forms.
Stars: ✭ 298 (-71.1%)
Mutual labels:  validation, form
Formsy React
A form input builder and validator for React JS
Stars: ✭ 708 (-31.33%)
Mutual labels:  validation, form

DocumentationLive DemoDemo CodeTutorialJoin Slack Workspace

MobX React Form

Reactive MobX Form State Management

Travis Build Codecov Coverage npm node GitHub license Downloads Downloads Backers on Open Collective Sponsors on Open Collective

NPM


Features

  • Extensibles Validation Plugins.
  • Sync & Async Validation (w/ Promises & automatic errors).
  • Nested Fields (w/ Serialization & Validation).
  • Nested Forms (w/ Nested Submission & Validation Hooks).
  • Event Hooks, Event Handlers & Validation Hooks
  • Observers & Interceptors
  • Bindings for custom Components.
  • Support for Material UI, React Widgets, React Select & more.
  • Dedicated DevTools Package.

Quick Start

Edit form-quickstart

npm install --save mobx-react-form

Choose and Setup a Validation Plugin

See Validation Plugins for more info on supported packages.

Below we are creating a plugins object using the validatorjs package to enable DVR functionalities (Declarative Validation Rules).

import dvr from 'mobx-react-form/lib/validators/DVR';
import validatorjs from 'validatorjs';

const plugins = {
  dvr: dvr(validatorjs)
};

Define the Form Fields

Define the fields as a collection with a rules property for the validation.

const fields = [{
  name: 'email',
  label: 'Email',
  placeholder: 'Insert Email',
  rules: 'required|email|string|between:5,25',
}, {
  name: 'password',
  label: 'Password',
  placeholder: 'Insert Password',
  rules: 'required|string|between:5,25',
}, {
  name: 'passwordConfirm',
  label: 'Password Confirmation',
  placeholder: 'Confirm Password',
  rules: 'required|string|same:password',
}];

You can also define fields as an object.

Define the Validation Hooks

const hooks = {
  onSuccess(form) {
    alert('Form is valid! Send the request here.');
    // get field values
    console.log('Form Values!', form.values());
  },
  onError(form) {
    alert('Form has errors!');
    // get all form errors
    console.log('All form errors', form.errors());
  }
}

Initialize the Form

Simply pass the fields, plugins and hooks objects to the constructor

import MobxReactForm from 'mobx-react-form';

const myForm = new MobxReactForm({ fields }, { plugins, hooks });

Pass the myForm to a react component

The package provide some built-in and ready to use Event Handlers:

onSubmit(e), onClear(e), onReset(e) & more...

import React from 'react';
import { observer } from 'mobx-react';

export default observer(({ myForm }) => (
  <form onSubmit={myForm.onSubmit}>
    <label htmlFor={myForm.$('email').id}>
      {myForm.$('email').label}
    </label>
    <input {...myForm.$('email').bind()} />
    <p>{myForm.$('email').error}</p>

    {/* ... other inputs ... */}

    <button type="submit" onClick={myForm.onSubmit}>Submit</button>
    <button type="button" onClick={myForm.onClear}>Clear</button>
    <button type="button" onClick={myForm.onReset}>Reset</button>

    <p>{myForm.error}</p>
  </form>
));

Other Field Props are available. See the docs for more details.

Extending the Form class

See how to implement the same configuration of this quickstart extending the Form class


Contributing

  1. Fork the repository
  2. Make applicable changes (with tests!)
  3. To run tests: yarn test
  4. Ensure builds succeed: yarn run build
  5. Commit via yarn to run pre-commit checks: yarn run commit

New Issues

When opening new issues, provide the setup of your form in a CodeSandbox.

These issues, and the ones which provides also PR with failing tests will get higher priority.

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

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].