react-mui-form-validator 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true
5
+ },
6
+ "extends": [
7
+ "plugin:react/recommended",
8
+ "airbnb-typescript",
9
+ "plugin:react/jsx-runtime",
10
+ "plugin:prettier/recommended"
11
+ ],
12
+ "parser": "@typescript-eslint/parser",
13
+ "parserOptions": {
14
+ "ecmaFeatures": {
15
+ "jsx": true
16
+ },
17
+ "ecmaVersion": 11,
18
+ "project": "./tsconfig.json",
19
+ "sourceType": "module"
20
+ },
21
+ "plugins": ["react", "@typescript-eslint"],
22
+ "settings": {
23
+ "react": {
24
+ "pragma": "React",
25
+ "fragment": "Fragment",
26
+ "version": "detect"
27
+ }
28
+ },
29
+ "rules": {
30
+ "prettier/prettier": "off",
31
+ "react/jsx-filename-extension": "off",
32
+ "import/no-unresolved": "off",
33
+ "import/extensions": "off",
34
+ "react/display-name": "off",
35
+ "@typescript-eslint/comma-dangle": "off",
36
+ "import/prefer-default-export": "off",
37
+ "jsx-a11y/anchor-is-valid": "off",
38
+ "comma-dangle": "off",
39
+ "max-len": "off",
40
+ "no-console": "off",
41
+ "no-param-reassign": "off",
42
+ "no-plusplus": "off",
43
+ "no-return-assign": "off",
44
+ "object-curly-newline": "off",
45
+ "react/jsx-props-no-spreading": "off",
46
+ "react/react-in-jsx-scope": "off",
47
+ "react/require-default-props": "off",
48
+ "typescript-eslint/no-unused-vars": "off",
49
+ "import/no-extraneous-dependencies": "off",
50
+ "react/no-unescaped-entities": "off",
51
+ "react/forbid-prop-types": "off",
52
+ "react/jsx-max-props-per-line": [
53
+ 1,
54
+ {
55
+ "maximum": 2,
56
+ "when": "multiline"
57
+ }
58
+ ],
59
+ "indent": "off",
60
+ "@typescript-eslint/indent": [0],
61
+ "no-use-before-define": "off",
62
+ "@typescript-eslint/no-use-before-define": ["off"],
63
+ "@typescript-eslint/no-unused-vars": ["off"],
64
+ "@typescript-eslint/no-shadow": ["off"],
65
+ "@typescript-eslint/dot-notation": ["off"],
66
+ "react/prop-types": ["off"],
67
+ "@typescript-eslint/naming-convention": ["off"]
68
+ }
69
+ }
package/Readme.md CHANGED
@@ -15,7 +15,7 @@ Some rules can accept extra parameter, example:
15
15
 
16
16
  TextField
17
17
  ```javascript
18
- <TextFieldValidator
18
+ <MuiTextField
19
19
  {...someProps}
20
20
  validators={["minNumber:0", "maxNumber:255", "matchRegexp:^[0-9]$"]}
21
21
  />
@@ -29,7 +29,7 @@ Your component must [provide a theme](http://www.material-ui.com/#/get-started/u
29
29
  ```javascript
30
30
  import React from "react";
31
31
  import Button from "@mui/material/Button";
32
- import { FormValidator, TextFieldValidator } from "react-mui-form-validator";
32
+ import { MuiForm, MuiTextField } from "react-mui-form-validator";
33
33
 
34
34
  class MyForm extends React.Component {
35
35
  state = {
@@ -48,11 +48,11 @@ class MyForm extends React.Component {
48
48
  render() {
49
49
  const { email } = this.state;
50
50
  return (
51
- <FormValidator
51
+ <MuiForm
52
52
  onSubmit={this.handleSubmit}
53
53
  onError={(errors) => console.log(errors)}
54
54
  >
55
- <TextFieldValidator
55
+ <MuiTextField
56
56
  label="Email"
57
57
  onChange={this.handleChange}
58
58
  name="email"
@@ -61,7 +61,7 @@ class MyForm extends React.Component {
61
61
  errorMessages={["this field is required", "email is not valid"]}
62
62
  />
63
63
  <Button type="submit">Submit</Button>
64
- </FormValidator>
64
+ </MuiForm>
65
65
  );
66
66
  }
67
67
  }
@@ -73,7 +73,7 @@ You can add your custom rules:
73
73
 
74
74
  import React from 'react';
75
75
  import Button from '@mui/material/Button';
76
- import { FormValidator, TextFieldValidator} from 'react-mui-form-validator';
76
+ import { MuiForm, MuiTextField} from 'react-mui-form-validator';
77
77
 
78
78
  class ResetPasswordForm extends React.Component {
79
79
 
@@ -86,7 +86,7 @@ class ResetPasswordForm extends React.Component {
86
86
 
87
87
  componentDidMount() {
88
88
  // custom rule will have name 'isPasswordMatch'
89
- FormValidator.addValidationRule('isPasswordMatch', (value) => {
89
+ MuiForm.addValidationRule('isPasswordMatch', (value) => {
90
90
  if (value !== this.state.user.password) {
91
91
  return false;
92
92
  }
@@ -96,7 +96,7 @@ class ResetPasswordForm extends React.Component {
96
96
 
97
97
  componentWillUnmount() {
98
98
  // remove rule when it is not needed
99
- FormValidator.removeValidationRule('isPasswordMatch');
99
+ MuiForm.removeValidationRule('isPasswordMatch');
100
100
  }
101
101
 
102
102
  handleChange = (event) => {
@@ -113,10 +113,10 @@ class ResetPasswordForm extends React.Component {
113
113
  const { user } = this.state;
114
114
 
115
115
  return (
116
- <FormValidator
116
+ <MuiForm
117
117
  onSubmit={this.handleSubmit}
118
118
  >
119
- <TextFieldValidator
119
+ <MuiTextField
120
120
  label="Password"
121
121
  onChange={this.handleChange}
122
122
  name="password"
@@ -125,7 +125,7 @@ class ResetPasswordForm extends React.Component {
125
125
  errorMessages={['this field is required']}
126
126
  value={user.password}
127
127
  />
128
- <TextFieldValidator
128
+ <MuiTextField
129
129
  label="Repeat password"
130
130
  onChange={this.handleChange}
131
131
  name="repeatPassword"
@@ -135,7 +135,7 @@ class ResetPasswordForm extends React.Component {
135
135
  value={user.repeatPassword}
136
136
  />
137
137
  <Button type="submit">Submit</Button>
138
- </FormValidator>
138
+ </MuiForm>
139
139
  );
140
140
  }
141
141
 
@@ -0,0 +1,122 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ declare class ValidatorComponent extends React.Component<any, any, any> {
5
+ static getDerivedStateFromProps(nextProps: any, prevState: any): {
6
+ value: any;
7
+ validators: any;
8
+ errorMessages: any;
9
+ } | {
10
+ value: any;
11
+ validators?: undefined;
12
+ errorMessages?: undefined;
13
+ };
14
+ constructor(props: any);
15
+ constructor(props: any, context: any);
16
+ state: {
17
+ isValid: boolean;
18
+ value: any;
19
+ errorMessages: any;
20
+ validators: any;
21
+ };
22
+ componentDidMount(): void;
23
+ shouldComponentUpdate(nextProps: any, nextState: any): boolean;
24
+ componentDidUpdate(prevProps: any, prevState: any): void;
25
+ componentWillUnmount(): void;
26
+ getErrorMessage: () => any;
27
+ instantValidate: boolean;
28
+ invalid: any[];
29
+ configure: () => void;
30
+ debounceTime: any;
31
+ validateDebounced: {
32
+ (value?: any, includeRequired?: boolean | undefined, dryRun?: boolean | undefined): void;
33
+ cancel: () => void;
34
+ } | undefined;
35
+ validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>;
36
+ isValid: () => boolean;
37
+ makeInvalid: () => void;
38
+ makeValid: () => void;
39
+ renderComponent: (form: any) => any;
40
+ form: any;
41
+ render(): React.JSX.Element;
42
+ }
43
+ declare namespace ValidatorComponent {
44
+ namespace propTypes {
45
+ let errorMessages: PropTypes.Requireable<NonNullable<string | any[] | null | undefined>>;
46
+ let validators: PropTypes.Requireable<any[]>;
47
+ let value: PropTypes.Requireable<any>;
48
+ let validatorListener: PropTypes.Requireable<(...args: any[]) => any>;
49
+ let withRequiredValidator: PropTypes.Requireable<boolean>;
50
+ let containerProps: PropTypes.Requireable<object>;
51
+ }
52
+ namespace defaultProps {
53
+ let errorMessages_1: string;
54
+ export { errorMessages_1 as errorMessages };
55
+ let validators_1: never[];
56
+ export { validators_1 as validators };
57
+ export function validatorListener_1(): void;
58
+ export { validatorListener_1 as validatorListener };
59
+ }
60
+ }
61
+
62
+ declare class TextValidator extends ValidatorComponent {
63
+ renderValidatorComponent(): React.JSX.Element;
64
+ }
65
+
66
+ declare class MuiSelect$1 extends ValidatorComponent {
67
+ renderValidatorComponent(): React.JSX.Element;
68
+ }
69
+
70
+ declare class ValidatorForm extends React.Component<any, any, any> {
71
+ static getValidator: (validator: any, value: any, includeRequired: any) => boolean;
72
+ constructor(props: any);
73
+ constructor(props: any, context: any);
74
+ getFormHelpers: () => {
75
+ form: {
76
+ attachToForm: (component: any) => void;
77
+ detachFromForm: (component: any) => void;
78
+ instantValidate: any;
79
+ debounceTime: any;
80
+ };
81
+ };
82
+ instantValidate: any;
83
+ debounceTime: any;
84
+ childs: any[];
85
+ errors: any[];
86
+ attachToForm: (component: any) => void;
87
+ detachFromForm: (component: any) => void;
88
+ submit: (event: any) => void;
89
+ walk: (children: any, dryRun: any) => Promise<any>;
90
+ checkInput: (input: any, dryRun: any) => Promise<any>;
91
+ validate: (input: any, includeRequired: any, dryRun: any) => Promise<any>;
92
+ find: (collection: any, fn: any) => any;
93
+ resetValidations: () => void;
94
+ isFormValid: (dryRun?: boolean) => Promise<any>;
95
+ render(): React.JSX.Element;
96
+ }
97
+ declare namespace ValidatorForm {
98
+ function addValidationRule(name: any, callback: any): void;
99
+ function getValidationRule(name: any): any;
100
+ function hasValidationRule(name: any): any;
101
+ function removeValidationRule(name: any): void;
102
+ namespace propTypes {
103
+ let onSubmit: PropTypes.Validator<(...args: any[]) => any>;
104
+ let instantValidate: PropTypes.Requireable<boolean>;
105
+ let children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
106
+ let onError: PropTypes.Requireable<(...args: any[]) => any>;
107
+ let debounceTime: PropTypes.Requireable<number>;
108
+ }
109
+ namespace defaultProps {
110
+ export function onError_1(): void;
111
+ export { onError_1 as onError };
112
+ let debounceTime_1: number;
113
+ export { debounceTime_1 as debounceTime };
114
+ }
115
+ }
116
+
117
+ declare const MuiTextField: typeof TextValidator;
118
+ declare const MuiSelect: typeof MuiSelect$1;
119
+ declare const MuiComponent: typeof ValidatorComponent;
120
+ declare const MuiForm: typeof ValidatorForm;
121
+
122
+ export { MuiComponent, MuiForm, MuiSelect, MuiTextField };