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

domain-react-forms

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

domain-react-forms

React Forms generator for Domain Schema

0.0.21
latest
Source
npm
Version published
Maintainers
1
Created
Source

Domain Schema Auto React Forms

npm version Twitter Follow

Installation

npm install -g domain-react-forms

##Usage

const userFormSchema = new DomainSchema(
  class User extends Schema {
    __ = { name: 'User' };
    id = DomainSchema.Int;
    username = {
      type: String,
      required: true,
      validators: [(value) => {
        return value.length > 3 ? undefined : 'Must Be more than 3 characters';
      }]
    };
    email = {
      type: String,
      required: true,
      email: true
    };
    profile = {
      type: Profile
    };
    password = {
      type: String,
      required: true,
      minLength: 5
    };
    passwordConfirmation = {
      type: String,
      required: true,
      minLength: 5,
      match: 'password'
    };
  }
);
class Profile extends Schema {
  __ = { name: 'Profile' };
  firstName = {
    type: String,
    required: {
      value: true,
      msg: 'Required First Name'
    }
  };
  lastName = {
      type: String,
      required: true
  };
};

const userForm =  new DomainReactForms(userFormSchema);

// change error messages
DomainReactForms.setValidationMessages({
  required: ({field}) => {
    return `Field '${field}' is required`
  }
});

const values = {
  // form values
};
const errors = userForm.validate(values);

License

Copyright © 2017 SysGears INC. This source code is licensed under the MIT license.

FAQs

Package last updated on 20 Feb 2018

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