domain-react-forms
v0.0.21
Published
React Forms generator for Domain Schema
Downloads
6
Readme
Domain Schema Auto React Forms
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.