Socket
Book a DemoInstallSign in
Socket

mui-form-validator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mui-form-validator

easy way to handle your forms with validation

1.0.4
latest
npmnpm
Version published
Weekly downloads
3
-40%
Maintainers
1
Weekly downloads
 
Created
Source

Validation component for material-ui v1 forms

npm version

Installation

npm install --save mui-form-validator

Versions

  • ^1.0.0 - supports material-ui >= ^1.4.x

Some rules can accept extra parameter, example:

<MuiValidator 
        {..someProps}
        inputProps={{required: true}}/>

Usage Example


/*
 * Created by Gihan
 */
import React, { Component } from "react";
/* Material UI Components */
import { MuiForm, MuiValidator } from "mui-form-validator";

class AddMember extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading : true,
            formData: {
                fname   : "",
                email   : "",
            },
            fields  : []
        };
        
        this.handleSubmit = this.handleSubmit.bind(this);
        this.handleChange = this.handleChange.bind(this);
        this.register = this.register.bind(this);
    }
    
    handleSubmit = (e) => {
        //Your submit handler
        //form data can get from state.fromData. you can change it as your own in handle change funcion
    };
    
    
    handleChange = (e) => {

        //setting form data to state.you can change it as your own.
        let formData = this.state.formData;
        formData[e.target.name] = e.target.value;
        this.setState({formData});
    };
    
    //register fields to validate (please add this function for register your form fields.this is required)
    register(field) {
        let s = this.state.fields;
        s.push(field);
        this.setState({fields: s});
    };
    
    render() {
        return (
            <MuiForm
                onSubmit={this.handleSubmit}
                noValidate>
                
                <MuiValidator placeholder={"First Name"} name={"fname"} type={"text"}
                                onChange={this.handleChange} value={this.state.formData.fname}
                                inputProps={{required: true}} onComponentMounted={this.register}
                                fullWidth={true}/>
            
                <MuiValidator placeholder={"Email"} name={"email"}
                                onChange={this.handleChange} value={this.state.formData.email}
                                inputProps={{required: true}} onComponentMounted={this.register}
                                fullWidth={true}/>
            
                <Button type={"submit"} variant={"raised"} color={"primary"}>Submit</Button>
                    
            </MuiForm>
        );
    }
    
}

  • onComponentMounted prop is required.please add it for MuiValidator component

Keywords

reactjs

FAQs

Package last updated on 17 Aug 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.