react-mui-form-validator 1.5.2 → 1.5.4
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/lib/index.d.ts +146 -147
- package/lib/index.js +77 -77
- package/package.json +16 -2
package/lib/index.d.ts
CHANGED
|
@@ -3,165 +3,164 @@ import React__default from 'react';
|
|
|
3
3
|
import { TextFieldVariants, FilledTextFieldProps, StandardTextFieldProps, OutlinedTextFieldProps } from '@mui/material';
|
|
4
4
|
import { MuiTelInputInfo } from 'mui-tel-input';
|
|
5
5
|
|
|
6
|
-
interface required {
|
|
7
|
-
validator: "required";
|
|
8
|
-
}
|
|
9
|
-
interface matchRegexp {
|
|
10
|
-
validator: "matchRegexp";
|
|
11
|
-
regexp: RegExp | string;
|
|
12
|
-
}
|
|
13
|
-
interface isEmail {
|
|
14
|
-
validator: "isEmail";
|
|
15
|
-
}
|
|
16
|
-
interface isEmpty {
|
|
17
|
-
validator: "isEmpty";
|
|
18
|
-
}
|
|
19
|
-
interface trim {
|
|
20
|
-
validator: "trim";
|
|
21
|
-
}
|
|
22
|
-
interface isNumber {
|
|
23
|
-
validator: "isNumber";
|
|
24
|
-
}
|
|
25
|
-
interface isFloat {
|
|
26
|
-
validator: "isFloat";
|
|
27
|
-
}
|
|
28
|
-
interface isPositive {
|
|
29
|
-
validator: "isPositive";
|
|
30
|
-
}
|
|
31
|
-
interface maxNumber {
|
|
32
|
-
validator: "maxNumber";
|
|
33
|
-
max: number;
|
|
34
|
-
}
|
|
35
|
-
interface minNumber {
|
|
36
|
-
validator: "minNumber";
|
|
37
|
-
min: number;
|
|
38
|
-
}
|
|
39
|
-
interface maxFloat {
|
|
40
|
-
validator: "maxFloat";
|
|
41
|
-
max: number;
|
|
42
|
-
}
|
|
43
|
-
interface minFloat {
|
|
44
|
-
validator: "minFloat";
|
|
45
|
-
min: number;
|
|
46
|
-
}
|
|
47
|
-
interface isString {
|
|
48
|
-
validator: "isString";
|
|
49
|
-
}
|
|
50
|
-
interface minStringLength {
|
|
51
|
-
validator: "minStringLength";
|
|
52
|
-
min: number;
|
|
53
|
-
}
|
|
54
|
-
interface maxStringLength {
|
|
55
|
-
validator: "maxStringLength";
|
|
56
|
-
max: number;
|
|
57
|
-
}
|
|
58
|
-
interface isFile {
|
|
59
|
-
validator: "isFile";
|
|
60
|
-
}
|
|
61
|
-
interface maxFileSize {
|
|
62
|
-
validator: "maxFileSize";
|
|
63
|
-
max: number;
|
|
64
|
-
}
|
|
65
|
-
interface allowedExtensions {
|
|
66
|
-
validator: "allowedExtensions";
|
|
67
|
-
fileTypes: string;
|
|
68
|
-
}
|
|
6
|
+
interface required {
|
|
7
|
+
validator: "required";
|
|
8
|
+
}
|
|
9
|
+
interface matchRegexp {
|
|
10
|
+
validator: "matchRegexp";
|
|
11
|
+
regexp: RegExp | string;
|
|
12
|
+
}
|
|
13
|
+
interface isEmail {
|
|
14
|
+
validator: "isEmail";
|
|
15
|
+
}
|
|
16
|
+
interface isEmpty {
|
|
17
|
+
validator: "isEmpty";
|
|
18
|
+
}
|
|
19
|
+
interface trim {
|
|
20
|
+
validator: "trim";
|
|
21
|
+
}
|
|
22
|
+
interface isNumber {
|
|
23
|
+
validator: "isNumber";
|
|
24
|
+
}
|
|
25
|
+
interface isFloat {
|
|
26
|
+
validator: "isFloat";
|
|
27
|
+
}
|
|
28
|
+
interface isPositive {
|
|
29
|
+
validator: "isPositive";
|
|
30
|
+
}
|
|
31
|
+
interface maxNumber {
|
|
32
|
+
validator: "maxNumber";
|
|
33
|
+
max: number;
|
|
34
|
+
}
|
|
35
|
+
interface minNumber {
|
|
36
|
+
validator: "minNumber";
|
|
37
|
+
min: number;
|
|
38
|
+
}
|
|
39
|
+
interface maxFloat {
|
|
40
|
+
validator: "maxFloat";
|
|
41
|
+
max: number;
|
|
42
|
+
}
|
|
43
|
+
interface minFloat {
|
|
44
|
+
validator: "minFloat";
|
|
45
|
+
min: number;
|
|
46
|
+
}
|
|
47
|
+
interface isString {
|
|
48
|
+
validator: "isString";
|
|
49
|
+
}
|
|
50
|
+
interface minStringLength {
|
|
51
|
+
validator: "minStringLength";
|
|
52
|
+
min: number;
|
|
53
|
+
}
|
|
54
|
+
interface maxStringLength {
|
|
55
|
+
validator: "maxStringLength";
|
|
56
|
+
max: number;
|
|
57
|
+
}
|
|
58
|
+
interface isFile {
|
|
59
|
+
validator: "isFile";
|
|
60
|
+
}
|
|
61
|
+
interface maxFileSize {
|
|
62
|
+
validator: "maxFileSize";
|
|
63
|
+
max: number;
|
|
64
|
+
}
|
|
65
|
+
interface allowedExtensions {
|
|
66
|
+
validator: "allowedExtensions";
|
|
67
|
+
fileTypes: string;
|
|
68
|
+
}
|
|
69
69
|
type Validator = required | matchRegexp | isEmail | isEmpty | trim | isNumber | isFloat | isPositive | maxNumber | minNumber | maxFloat | minFloat | isString | minStringLength | maxStringLength | isFile | maxFileSize | allowedExtensions;
|
|
70
70
|
|
|
71
|
-
type MuiTextFieldProps<Variant extends TextFieldVariants = TextFieldVariants> = Variant extends "filled" ? FilledTextFieldProps : Variant extends "standard" ? StandardTextFieldProps : OutlinedTextFieldProps & ValidatorComponentProps;
|
|
72
|
-
interface ValidatorComponentProps {
|
|
73
|
-
errorMessages?: string | string[];
|
|
74
|
-
validators?: Validator[];
|
|
75
|
-
value: any;
|
|
76
|
-
validatorListener?: (value: boolean) => void;
|
|
77
|
-
withRequiredValidator?: boolean;
|
|
78
|
-
containerProps?: object;
|
|
79
|
-
onChangeTel?: (value: string, info: MuiTelInputInfo) => void;
|
|
80
|
-
}
|
|
81
|
-
interface ValidatorComponentState {
|
|
82
|
-
isValid?: boolean;
|
|
83
|
-
value: any;
|
|
84
|
-
errorMessages?: string | string[];
|
|
85
|
-
validators?: Validator[];
|
|
86
|
-
}
|
|
87
|
-
interface ValidatorFormProps {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
onError?: (errors: any
|
|
92
|
-
debounceTime?: number;
|
|
71
|
+
type MuiTextFieldProps<Variant extends TextFieldVariants = TextFieldVariants> = Variant extends "filled" ? FilledTextFieldProps : Variant extends "standard" ? StandardTextFieldProps : OutlinedTextFieldProps & ValidatorComponentProps;
|
|
72
|
+
interface ValidatorComponentProps {
|
|
73
|
+
errorMessages?: string | string[];
|
|
74
|
+
validators?: Validator[];
|
|
75
|
+
value: any;
|
|
76
|
+
validatorListener?: (value: boolean) => void;
|
|
77
|
+
withRequiredValidator?: boolean;
|
|
78
|
+
containerProps?: object;
|
|
79
|
+
onChangeTel?: (value: string, info: MuiTelInputInfo) => void;
|
|
80
|
+
}
|
|
81
|
+
interface ValidatorComponentState {
|
|
82
|
+
isValid?: boolean;
|
|
83
|
+
value: any;
|
|
84
|
+
errorMessages?: string | string[];
|
|
85
|
+
validators?: Validator[];
|
|
86
|
+
}
|
|
87
|
+
interface ValidatorFormProps {
|
|
88
|
+
children: React.ReactNode;
|
|
89
|
+
onSubmit: () => void;
|
|
90
|
+
instantValidate?: boolean;
|
|
91
|
+
onError?: (errors: any) => void;
|
|
92
|
+
debounceTime?: number;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
declare class ValidatorForm extends React$1.Component<ValidatorFormProps> {
|
|
96
|
-
static getValidator: (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
attachToForm: (component: any) => void;
|
|
110
|
-
detachFromForm: (component: any) => void;
|
|
111
|
-
submit: (event: React$1.FormEvent<HTMLFormElement>) => void;
|
|
112
|
-
walk: (children: any[], dryRun?: boolean) => Promise<boolean>;
|
|
113
|
-
checkInput: (input: any, dryRun?: boolean) => Promise<boolean>;
|
|
114
|
-
validate: (input: any, includeRequired: boolean, dryRun?: boolean) => Promise<boolean>;
|
|
115
|
-
find: (collection: any[], fn: (item: any) => boolean) => any;
|
|
116
|
-
resetValidations: () => void;
|
|
117
|
-
isFormValid: (dryRun?: boolean) => Promise<boolean>;
|
|
118
|
-
render(): React$1.JSX.Element;
|
|
95
|
+
declare class ValidatorForm extends React$1.Component<ValidatorFormProps> {
|
|
96
|
+
static getValidator: (validator: Validator, value: any, includeRequired: boolean) => boolean;
|
|
97
|
+
getFormHelpers: () => {
|
|
98
|
+
form: {
|
|
99
|
+
attachToForm: (component: any) => void;
|
|
100
|
+
detachFromForm: (component: any) => void;
|
|
101
|
+
instantValidate: boolean;
|
|
102
|
+
debounceTime: number;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
instantValidate: boolean;
|
|
106
|
+
childs: any[];
|
|
107
|
+
errors: any[];
|
|
108
|
+
debounceTime: number;
|
|
109
|
+
attachToForm: (component: any) => void;
|
|
110
|
+
detachFromForm: (component: any) => void;
|
|
111
|
+
submit: (event: React$1.FormEvent<HTMLFormElement>) => void;
|
|
112
|
+
walk: (children: any[], dryRun?: boolean) => Promise<boolean>;
|
|
113
|
+
checkInput: (input: any, dryRun?: boolean) => Promise<boolean>;
|
|
114
|
+
validate: (input: any, includeRequired: boolean, dryRun?: boolean) => Promise<boolean>;
|
|
115
|
+
find: (collection: any[], fn: (item: any) => boolean) => any;
|
|
116
|
+
resetValidations: () => void;
|
|
117
|
+
isFormValid: (dryRun?: boolean) => Promise<boolean>;
|
|
118
|
+
render(): React$1.JSX.Element;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
declare class ValidatorComponent extends React$1.Component<MuiTextFieldProps & ValidatorComponentProps, ValidatorComponentState> {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
validators
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
render(): React$1.JSX.Element;
|
|
121
|
+
declare class ValidatorComponent extends React$1.Component<MuiTextFieldProps & ValidatorComponentProps, ValidatorComponentState> {
|
|
122
|
+
[x: string]: any;
|
|
123
|
+
getSnapshotBeforeUpdate(nextProps: ValidatorComponentProps, prevState: ValidatorComponentState): {
|
|
124
|
+
value: any;
|
|
125
|
+
validators: Validator[];
|
|
126
|
+
errorMessages: string | string[];
|
|
127
|
+
} | {
|
|
128
|
+
value: any;
|
|
129
|
+
validators?: undefined;
|
|
130
|
+
errorMessages?: undefined;
|
|
131
|
+
};
|
|
132
|
+
state: {
|
|
133
|
+
isValid: boolean;
|
|
134
|
+
value: any;
|
|
135
|
+
errorMessages: string | string[] | undefined;
|
|
136
|
+
validators: Validator[] | undefined;
|
|
137
|
+
};
|
|
138
|
+
componentDidMount(): void;
|
|
139
|
+
shouldComponentUpdate(nextProps: ValidatorComponentProps, nextState: ValidatorComponentState): boolean;
|
|
140
|
+
componentDidUpdate(prevProps: ValidatorComponentProps, prevState: ValidatorComponentState): void;
|
|
141
|
+
componentWillUnmount(): void;
|
|
142
|
+
getErrorMessage: () => string | boolean | string[];
|
|
143
|
+
instantValidate: boolean;
|
|
144
|
+
invalid: number[];
|
|
145
|
+
configure: () => void;
|
|
146
|
+
validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>;
|
|
147
|
+
isValid: () => boolean;
|
|
148
|
+
makeInvalid: () => void;
|
|
149
|
+
makeValid: () => void;
|
|
150
|
+
renderComponent: (form: ValidatorForm) => React$1.ReactNode;
|
|
151
|
+
render(): React$1.JSX.Element;
|
|
153
152
|
}
|
|
154
153
|
|
|
155
|
-
declare class MuiSelect extends ValidatorComponent {
|
|
156
|
-
renderValidatorComponent(): React$1.JSX.Element;
|
|
154
|
+
declare class MuiSelect extends ValidatorComponent {
|
|
155
|
+
renderValidatorComponent(): React$1.JSX.Element;
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
declare class MuiTextField extends ValidatorComponent {
|
|
160
|
-
renderValidatorComponent(): React__default.JSX.Element;
|
|
158
|
+
declare class MuiTextField extends ValidatorComponent {
|
|
159
|
+
renderValidatorComponent(): React__default.JSX.Element;
|
|
161
160
|
}
|
|
162
161
|
|
|
163
|
-
declare class MuiTelInputDefault extends ValidatorComponent {
|
|
164
|
-
renderValidatorComponent(): React__default.JSX.Element;
|
|
162
|
+
declare class MuiTelInputDefault extends ValidatorComponent {
|
|
163
|
+
renderValidatorComponent(): React__default.JSX.Element;
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
export { ValidatorComponent as MuiComponent, ValidatorForm as MuiForm, MuiTelInputDefault as MuiPhoneNumber, MuiSelect, MuiTextField, Validator as MuiValidator };
|
package/lib/index.js
CHANGED
|
@@ -17372,69 +17372,68 @@ var validations = {
|
|
|
17372
17372
|
maxFileSize: (value, max) => isEmpty6(value) || validations.isFile(value) && value.size <= parseInt(max.toString(), 10),
|
|
17373
17373
|
allowedExtensions: (value, fileTypes) => isEmpty6(value) || validations.isFile(value) && fileTypes.split(",").indexOf(value.type) !== -1
|
|
17374
17374
|
};
|
|
17375
|
-
var ValidationRules_default = validations;
|
|
17376
17375
|
|
|
17377
17376
|
// src/core/validator/ValidatorForm.tsx
|
|
17378
17377
|
var FormContext = React61.createContext("form");
|
|
17379
17378
|
var ValidatorForm = class extends React61.Component {
|
|
17380
|
-
static getValidator = (
|
|
17379
|
+
static getValidator = (validator2, value, includeRequired) => {
|
|
17381
17380
|
let valid = validator2;
|
|
17382
17381
|
let result = true;
|
|
17383
17382
|
if (valid.validator !== "required" || includeRequired) {
|
|
17384
17383
|
switch (valid.validator) {
|
|
17385
17384
|
case "required":
|
|
17386
|
-
result =
|
|
17385
|
+
result = validations.required(value);
|
|
17387
17386
|
break;
|
|
17388
17387
|
case "isEmail":
|
|
17389
|
-
result =
|
|
17388
|
+
result = validations.isEmail(value);
|
|
17390
17389
|
break;
|
|
17391
17390
|
case "isEmpty":
|
|
17392
|
-
result =
|
|
17391
|
+
result = validations.isEmpty(value);
|
|
17393
17392
|
break;
|
|
17394
17393
|
case "allowedExtensions":
|
|
17395
|
-
result =
|
|
17394
|
+
result = validations.allowedExtensions(value, valid.fileTypes);
|
|
17396
17395
|
break;
|
|
17397
17396
|
case "isFile":
|
|
17398
|
-
result =
|
|
17397
|
+
result = validations.isFile(value);
|
|
17399
17398
|
break;
|
|
17400
17399
|
case "isFloat":
|
|
17401
|
-
result =
|
|
17400
|
+
result = validations.isFloat(value);
|
|
17402
17401
|
break;
|
|
17403
17402
|
case "isNumber":
|
|
17404
|
-
result =
|
|
17403
|
+
result = validations.isNumber(value);
|
|
17405
17404
|
break;
|
|
17406
17405
|
case "isPositive":
|
|
17407
|
-
result =
|
|
17406
|
+
result = validations.isPositive(value);
|
|
17408
17407
|
break;
|
|
17409
17408
|
case "isString":
|
|
17410
|
-
result =
|
|
17409
|
+
result = validations.isString(value);
|
|
17411
17410
|
break;
|
|
17412
17411
|
case "matchRegexp":
|
|
17413
|
-
result =
|
|
17412
|
+
result = validations.matchRegexp(value, valid.regexp);
|
|
17414
17413
|
break;
|
|
17415
17414
|
case "maxFileSize":
|
|
17416
|
-
result =
|
|
17415
|
+
result = validations.maxFileSize(value, valid.max);
|
|
17417
17416
|
break;
|
|
17418
17417
|
case "maxFloat":
|
|
17419
|
-
result =
|
|
17418
|
+
result = validations.maxFloat(value, valid.max);
|
|
17420
17419
|
break;
|
|
17421
17420
|
case "maxNumber":
|
|
17422
|
-
result =
|
|
17421
|
+
result = validations.maxNumber(value, valid.max);
|
|
17423
17422
|
break;
|
|
17424
17423
|
case "maxStringLength":
|
|
17425
|
-
result =
|
|
17424
|
+
result = validations.maxStringLength(value, valid.max);
|
|
17426
17425
|
break;
|
|
17427
17426
|
case "minFloat":
|
|
17428
|
-
result =
|
|
17427
|
+
result = validations.minFloat(value, valid.min);
|
|
17429
17428
|
break;
|
|
17430
17429
|
case "minNumber":
|
|
17431
|
-
result =
|
|
17430
|
+
result = validations.minNumber(value, valid.min);
|
|
17432
17431
|
break;
|
|
17433
17432
|
case "minStringLength":
|
|
17434
|
-
result =
|
|
17433
|
+
result = validations.minStringLength(value, valid.min);
|
|
17435
17434
|
break;
|
|
17436
17435
|
case "trim":
|
|
17437
|
-
result =
|
|
17436
|
+
result = validations.trim(value);
|
|
17438
17437
|
break;
|
|
17439
17438
|
default:
|
|
17440
17439
|
result = true;
|
|
@@ -17443,18 +17442,18 @@ var ValidatorForm = class extends React61.Component {
|
|
|
17443
17442
|
}
|
|
17444
17443
|
return result;
|
|
17445
17444
|
};
|
|
17446
|
-
childs = [];
|
|
17447
|
-
errors = [];
|
|
17448
|
-
instantValidate = this.props.instantValidate !== void 0 ? this.props.instantValidate : true;
|
|
17449
|
-
debounceTime = this.props.debounceTime;
|
|
17450
17445
|
getFormHelpers = () => ({
|
|
17451
17446
|
form: {
|
|
17452
17447
|
attachToForm: this.attachToForm,
|
|
17453
|
-
debounceTime: this.props.debounceTime,
|
|
17454
17448
|
detachFromForm: this.detachFromForm,
|
|
17455
|
-
instantValidate: this.
|
|
17449
|
+
instantValidate: this.instantValidate,
|
|
17450
|
+
debounceTime: this.debounceTime
|
|
17456
17451
|
}
|
|
17457
17452
|
});
|
|
17453
|
+
instantValidate = this.props.instantValidate !== void 0 ? this.props.instantValidate : true;
|
|
17454
|
+
childs = [];
|
|
17455
|
+
errors = [];
|
|
17456
|
+
debounceTime = this.props.debounceTime !== void 0 ? this.props.debounceTime : 0;
|
|
17458
17457
|
attachToForm = (component) => {
|
|
17459
17458
|
if (this.childs.indexOf(component) === -1) {
|
|
17460
17459
|
this.childs.push(component);
|
|
@@ -17474,7 +17473,9 @@ var ValidatorForm = class extends React61.Component {
|
|
|
17474
17473
|
this.errors = [];
|
|
17475
17474
|
this.walk(this.childs).then((result) => {
|
|
17476
17475
|
if (this.errors.length) {
|
|
17477
|
-
this.props.onError
|
|
17476
|
+
if (this.props.onError != void 0) {
|
|
17477
|
+
this.props.onError(this.errors);
|
|
17478
|
+
}
|
|
17478
17479
|
}
|
|
17479
17480
|
if (result) {
|
|
17480
17481
|
this.props.onSubmit();
|
|
@@ -17584,21 +17585,6 @@ var debounce2 = (func, wait, immediate) => {
|
|
|
17584
17585
|
|
|
17585
17586
|
// src/core/validator/ValidatorComponent.tsx
|
|
17586
17587
|
var ValidatorComponent = class extends React62.Component {
|
|
17587
|
-
renderValidatorComponent() {
|
|
17588
|
-
throw new Error("Method not implemented.");
|
|
17589
|
-
}
|
|
17590
|
-
form;
|
|
17591
|
-
debounceTime;
|
|
17592
|
-
validateDebounced;
|
|
17593
|
-
constructor(props) {
|
|
17594
|
-
super(props);
|
|
17595
|
-
this.state = {
|
|
17596
|
-
isValid: true,
|
|
17597
|
-
value: this.props.value,
|
|
17598
|
-
errorMessages: this.props.errorMessages,
|
|
17599
|
-
validators: this.props.validators
|
|
17600
|
-
};
|
|
17601
|
-
}
|
|
17602
17588
|
getSnapshotBeforeUpdate(nextProps, prevState) {
|
|
17603
17589
|
if (nextProps.validators && nextProps.errorMessages && (prevState.validators !== nextProps.validators || prevState.errorMessages !== nextProps.errorMessages)) {
|
|
17604
17590
|
return {
|
|
@@ -17611,17 +17597,15 @@ var ValidatorComponent = class extends React62.Component {
|
|
|
17611
17597
|
value: nextProps.value
|
|
17612
17598
|
};
|
|
17613
17599
|
}
|
|
17614
|
-
|
|
17615
|
-
|
|
17600
|
+
state = {
|
|
17601
|
+
isValid: true,
|
|
17602
|
+
value: this.props.value,
|
|
17603
|
+
errorMessages: this.props.errorMessages,
|
|
17604
|
+
validators: this.props.validators
|
|
17605
|
+
};
|
|
17616
17606
|
componentDidMount() {
|
|
17617
17607
|
this.configure();
|
|
17618
17608
|
}
|
|
17619
|
-
configure = () => {
|
|
17620
|
-
this.form.attachToForm(this);
|
|
17621
|
-
this.instantValidate = this.form.instantValidate;
|
|
17622
|
-
this.debounceTime = this.form.debounceTime;
|
|
17623
|
-
this.validateDebounced = debounce2(this.validate, this.debounceTime);
|
|
17624
|
-
};
|
|
17625
17609
|
shouldComponentUpdate(nextProps, nextState) {
|
|
17626
17610
|
return this.state !== nextState || this.props !== nextProps;
|
|
17627
17611
|
}
|
|
@@ -17640,41 +17624,57 @@ var ValidatorComponent = class extends React62.Component {
|
|
|
17640
17624
|
getErrorMessage = () => {
|
|
17641
17625
|
const { errorMessages } = this.state;
|
|
17642
17626
|
const type = typeof errorMessages;
|
|
17643
|
-
if (
|
|
17644
|
-
|
|
17645
|
-
|
|
17646
|
-
if (
|
|
17647
|
-
|
|
17627
|
+
if (errorMessages) {
|
|
17628
|
+
if (type === "string") {
|
|
17629
|
+
return errorMessages;
|
|
17630
|
+
} else if (type === "object") {
|
|
17631
|
+
if (this.invalid.length > 0) {
|
|
17632
|
+
return errorMessages[this.invalid[0]];
|
|
17633
|
+
}
|
|
17648
17634
|
}
|
|
17649
17635
|
}
|
|
17650
17636
|
return true;
|
|
17651
17637
|
};
|
|
17638
|
+
instantValidate = true;
|
|
17639
|
+
invalid = [];
|
|
17640
|
+
configure = () => {
|
|
17641
|
+
this.form.attachToForm(this);
|
|
17642
|
+
this.instantValidate = this.form.instantValidate;
|
|
17643
|
+
this.debounceTime = this.form.debounceTime;
|
|
17644
|
+
this.validateDebounced = debounce2(this.validate, this.debounceTime);
|
|
17645
|
+
};
|
|
17652
17646
|
validate = async (value, includeRequired = false, dryRun = false) => {
|
|
17653
|
-
|
|
17654
|
-
|
|
17655
|
-
|
|
17656
|
-
|
|
17657
|
-
|
|
17658
|
-
|
|
17659
|
-
|
|
17660
|
-
|
|
17661
|
-
|
|
17662
|
-
|
|
17663
|
-
|
|
17664
|
-
|
|
17665
|
-
|
|
17666
|
-
|
|
17667
|
-
|
|
17668
|
-
|
|
17669
|
-
|
|
17670
|
-
|
|
17671
|
-
|
|
17672
|
-
|
|
17647
|
+
if (this.state.validators) {
|
|
17648
|
+
const validations2 = Promise.all(
|
|
17649
|
+
this.state.validators.map(
|
|
17650
|
+
(validator2) => ValidatorForm_default.getValidator(validator2, value, includeRequired)
|
|
17651
|
+
)
|
|
17652
|
+
);
|
|
17653
|
+
return validations2.then((results) => {
|
|
17654
|
+
this.invalid = [];
|
|
17655
|
+
let valid = true;
|
|
17656
|
+
results.forEach((result, key) => {
|
|
17657
|
+
if (!result) {
|
|
17658
|
+
valid = false;
|
|
17659
|
+
this.invalid.push(key);
|
|
17660
|
+
}
|
|
17661
|
+
});
|
|
17662
|
+
if (!dryRun) {
|
|
17663
|
+
this.setState({ isValid: valid }, () => {
|
|
17664
|
+
if (this.props.validatorListener != void 0) {
|
|
17665
|
+
this.props.validatorListener(
|
|
17666
|
+
this.state.isValid === void 0 ? true : this.state.isValid
|
|
17667
|
+
);
|
|
17668
|
+
}
|
|
17669
|
+
});
|
|
17670
|
+
}
|
|
17671
|
+
return valid;
|
|
17673
17672
|
});
|
|
17673
|
+
} else {
|
|
17674
|
+
return true;
|
|
17674
17675
|
}
|
|
17675
|
-
return valid;
|
|
17676
17676
|
};
|
|
17677
|
-
isValid = () => this.state.isValid === void 0 ?
|
|
17677
|
+
isValid = () => this.state.isValid === void 0 ? true : this.state.isValid;
|
|
17678
17678
|
makeInvalid = () => {
|
|
17679
17679
|
this.setState({ isValid: false });
|
|
17680
17680
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-mui-form-validator",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "Validator for forms designed with material-ui components.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"prod": "rimraf ./lib && tsup src/index.ts --dts --outDir=lib",
|
|
9
|
+
"start": "react-scripts start",
|
|
9
10
|
"test": "jest",
|
|
10
11
|
"test:watch": "jest --watch"
|
|
11
12
|
},
|
|
@@ -46,6 +47,19 @@
|
|
|
46
47
|
"mui-tel-input": "4.0.1",
|
|
47
48
|
"rimraf": "^5.0.5",
|
|
48
49
|
"tsup": "^7.2.0",
|
|
49
|
-
"
|
|
50
|
+
"react-scripts": "5.0.1",
|
|
51
|
+
"typescript": "^4.9.5"
|
|
52
|
+
},
|
|
53
|
+
"browserslist": {
|
|
54
|
+
"production": [
|
|
55
|
+
">0.2%",
|
|
56
|
+
"not dead",
|
|
57
|
+
"not op_mini all"
|
|
58
|
+
],
|
|
59
|
+
"development": [
|
|
60
|
+
"last 1 chrome version",
|
|
61
|
+
"last 1 firefox version",
|
|
62
|
+
"last 1 safari version"
|
|
63
|
+
]
|
|
50
64
|
}
|
|
51
65
|
}
|