🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

react-mui-form-validator

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-mui-form-validator

Validator for forms designed with material-ui components.

Source
npmnpm
Version
1.5.6
Version published
Weekly downloads
10
-67.74%
Maintainers
1
Weekly downloads
 
Created
Source

Validation component for material-ui forms

license

Installation

npm install react-mui-form-validator

Info

Some rules can accept extra parameter, example:

TextField

<MuiTextField
  {...someProps}
  validators={[
    {
      validator: "maxNumber",
      max: 10,
    },
  ]}
/>

Usage Example

You can pass any props of field components, but note that errorText prop will be replaced when validation errors occurred. Your component must provide a theme.

import { useState } from "react";
import { MuiForm, MuiTextField } from "react-mui-form-validator";
import { Button } from "@mui/material";

export default function App(props: any) {
  const [email, setEmail] = useState();

  const handleSubmit = () => {
    // your submit logic
  };

  return (
    <div>
      <h3>Example Sign In</h3>
      <MuiForm
        onSubmit={handleSubmit}
        onError={(errors: any) => console.log(errors)}
      >
        <MuiTextField
          name="email"
          label="Email"
          placeholder="example@domain.com"
          onChange={(v) => setEmail(v.target.value)}
          value={email}
          validators={[{ validator: "required" }, { validator: "isEmail" }]}
          errorMessages={["Email required", "Enter a valid email"]}
          fullWidth
        />
        <br />
        <Button type="submit" variant="outlined">
          Sign In
        </Button>
      </MuiForm>
    </div>
  );
}

Keywords

react

FAQs

Package last updated on 07 Nov 2023

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