1.5.7 • Published 6 months ago

react-mui-form-validator v1.5.7

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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>
  );
}
1.5.5

6 months ago

1.5.4

6 months ago

1.5.3

6 months ago

1.5.2

6 months ago

1.5.1

6 months ago

1.5.0

6 months ago

1.5.7

6 months ago

1.5.6

6 months ago

1.2.0

9 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.1.9

9 months ago

1.1.7

10 months ago

1.1.5

10 months ago

1.0.6

10 months ago

1.1.3

10 months ago

1.2.1

9 months ago

1.1.2

10 months ago

1.0.5

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago