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

material-ui-react-form

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

material-ui-react-form

0.0.6
latest
Source
npm
Version published
Weekly downloads
163
-10.44%
Maintainers
1
Weekly downloads
 
Created
Source
import React from "react";
import { render } from "react-dom";
import { Button, TextField } from "@material-ui/core";
import { useForm } from "material-ui-react-form";

function App() {
    const [fields, form] = useForm({
        name: { test: "required", message: "Name is required" },
        email: { test: ["required", "email"], message: "Enter valid email" },
        phone: { test: /^[0-9]${10}/, message: "Enter valid phone" },
    });

    useEffect(() => {
        // set value dynamically
        form.setValues({name: "Some invalid name"})

        // set error dynamically
        form.setErrors({name: 'Name is not valid'});
    }, []);

    const handleSave = () => {
        const values = form.validate();
        if (!values) {
            return;
        }
        console.log(values) // {name: "some name", email: "some email", phone: "some phone"}
    }
    return (
        <div>
            <TextField {...fields.name} placeholder="Say my name" fullWidth />
            <TextField {...fields.email} placeholder="Email" fullWidth />
            <TextField {...fields.phone} placeholder="Phone" fullWidth />
            <Button onClick={handleSave}>Save</Button>
        </div>
    )
}

render(<App />, document.getElementById('root'));

Keywords

material ui

FAQs

Package last updated on 11 May 2021

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