All Projects → MinJieLiu → react-validate-framework

MinJieLiu / react-validate-framework

Licence: MIT license
A lightweight and extensible React validation component

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to react-validate-framework

Nager.publicsuffix
.NET publicsuffix domain parser
Stars: ✭ 67 (+272.22%)
Mutual labels:  validate
react-antd-formutil
Happy to use react-formutil in the project based on ant-design ^_^
Stars: ✭ 16 (-11.11%)
Mutual labels:  react-form
valite
🔥 Concurrently execute your validators in a simple, practical and light validator engine.
Stars: ✭ 20 (+11.11%)
Mutual labels:  validate
Checkssl
checks ssl certs for a set of domains
Stars: ✭ 86 (+377.78%)
Mutual labels:  validate
Php Validate
Lightweight and feature-rich PHP validation and filtering library. Support scene grouping, pre-filtering, array checking, custom validators, custom messages. 轻量且功能丰富的PHP验证、过滤库。支持场景分组,前置过滤,数组检查,自定义验证器,自定义消息。
Stars: ✭ 225 (+1150%)
Mutual labels:  validate
reach-schema
Functional schema-driven JavaScript object validation library.
Stars: ✭ 34 (+88.89%)
Mutual labels:  validate
Creditcard
Creditcard number parsing, validation and information extraction
Stars: ✭ 52 (+188.89%)
Mutual labels:  validate
cashaddress
Python tool for convert bitcoin cash legacy addresses
Stars: ✭ 40 (+122.22%)
Mutual labels:  validate
Password Validator
Validates password according to flexible and intuitive specification
Stars: ✭ 224 (+1144.44%)
Mutual labels:  validate
swagger-editor-validate
This GitHub Actions validates OpenAPI (OAS) definition file using Swagger Editor.
Stars: ✭ 30 (+66.67%)
Mutual labels:  validate
Bootstrap Validate
A simple Form Validation Library for Bootstrap 3 and Bootstrap 4 not depending on jQuery.
Stars: ✭ 112 (+522.22%)
Mutual labels:  validate
Vue Dynamic Form Component
Vue dynamic nested form component, support nested Object/Hashmap/Array. Vue动态多级表单组件,支持嵌套对象/Hashmap/数组。
Stars: ✭ 220 (+1122.22%)
Mutual labels:  validate
FilterInputJs
Tiny and Powerful Library for limit an entry (text box,input) as number,string or more...
Stars: ✭ 37 (+105.56%)
Mutual labels:  validate
Angular Validate
Painless form validation for AngularJS. Powered by the jQuery Validation Plugin.
Stars: ✭ 71 (+294.44%)
Mutual labels:  validate
ree-validate
Simple React.js input validation plugin extended from vee-validate
Stars: ✭ 16 (-11.11%)
Mutual labels:  react-validate
Vee Validate
✅ Form Validation for Vue.js
Stars: ✭ 8,820 (+48900%)
Mutual labels:  validate
React-Netflix-Clone
A Fully Responsive clone of Netflix website built using React.JS as a Front-end & Firebase as a Back-end.
Stars: ✭ 91 (+405.56%)
Mutual labels:  react-forms
react-formulation
Simple React form validation
Stars: ✭ 14 (-22.22%)
Mutual labels:  validate
cognito-jwt-verifier
Verify ID and access JWT tokens from AWS Cognito in your node/Lambda backend with minimal dependencies.
Stars: ✭ 25 (+38.89%)
Mutual labels:  validate
talos
Elixir parameter validation library. Simple and extensible
Stars: ✭ 23 (+27.78%)
Mutual labels:  validate

react-validate-framework

A lightweight and extensible React validation component

npm travis-ci Coverage Status npm

中文 README

Demo: https://minjieliu.github.io/react-validate-framework

You can check out the code to see examples.

How to use?

npm i react-validate-framework --save

Import:

import formConnect, {
  Checkbox,
  Radio,
  Select,
  Text,
  Textarea,
  Message,
} from 'react-validate-framework';

Rules and messages like this:

const schemas = {
  email: {
    rules: 'required | isEmail | maxLength(32) | validateFromServer',
    messages: 'Can not be empty! | Please enter a valid email address. | Can not exceed {{param}} characters. | | The email already exists.',
  },
  hobby: {
    rules: 'requiredField(phone) | selectLimit(2)',
    messages: 'email and hobby at least one entry! | Select at least {{param}}.',
  },
};

const methods = {
  selectLimit(field, param) {
    if (Array.isArray(field.value)) {
      return field.value.length >= param;
    }
    return false;
  },
  requiredField(field, param) {
    const otherField = this.fields[param];
    return this.required(field) || (otherField.result && this.required(otherField));
  },
  async validateFromServer(field, param) {
    return await doServerAPI();
  },
};

The BasicForm like this:

@formConnect(schemas, methods)
export default class BasicForm extends React.Component {
  
  static propTypes = {
    formControl: PropTypes.object,
  };

  constructor(props) {
    super(props);
    props.formControl.init({
      email: '',
      phone: '',
    }, {
      static: 'form-control',
      success: 'valid-success',
      error: 'valid-error',
    });
  }

  handleSubmit = async () => {
    const { formControl } = this.props;
    if (await formControl.validate()) {
      // Submit.
    }
  };

  render() {
    return (
      <div className="form-group">
        <Text
          name="email"
          placeholder="Please input your email"
          delay={100} // Asynchronous validation
        />
        <Message className="valid-error-message" name="email" />
        <Text name="phone" />
        <button onClick={this.handleSubmit}>提交</button>
      </div>
    );
  }
}

Validate methods can refer to validate-framework-utils

Form components

  • Checkbox
  • Radio
  • Select
  • Text
  • Textarea
  • Message

The name attribute is required in form components, delay debounce, Other parameters can be overridden.

Of course, you can also use unencapsulated form components, just specify value and onChange on the line:

const {
  formControl: {
    fields,
    onFormChange,
  },
} = this.props;

return (
  <input
    className={fields.email.className}
    name="email"
    type="text"
    onChange={onFormChange}
    value={fields.email.value}
    placeholder="Please input your email"
  />
);

API

Form params

name type return setState description
fields Object The collection of fields
isAllValid Boolean Gets the global validation status
formValues Object Gets a list of form values
init function this Initializes the form value and classes
initClassNames function this false Initializes classes
onFormChange function true Form change event listener
changeValues function this true Customize to change the values
validate function Promise => Boolean true Validate all fields
validateByNames function Promise => Boolean true Validate the component through names
addValues function this true Add one or more value
removeValues function this true Remove one or more value, If there is no name, it will all be removed
resetValues function this true Reset one or more value, If there is no name, it will all be init
addSchemas function this false Add one or more validation rules
removeSchemas function this true Remove one or more validation rules, If there is no name, it will all be removed
formDidChange function Callback

You can invoke the changeValues method to simulate a form change event.

Update log

0.15.x

  • Remove the delay parameter from FormControl.
  • Add the delay parameter to the props of the form component.
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].