react-mui-form-validator 1.5.1 → 1.5.3
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 +122 -99
- package/package.json +18 -5
- package/tsconfig.json +2 -1
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: (value: any,
|
|
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,66 +17372,88 @@ 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 = (value,
|
|
17379
|
+
static getValidator = (validator2, value, includeRequired) => {
|
|
17381
17380
|
let valid = validator2;
|
|
17382
|
-
|
|
17383
|
-
|
|
17384
|
-
|
|
17385
|
-
|
|
17386
|
-
|
|
17387
|
-
|
|
17388
|
-
|
|
17389
|
-
|
|
17390
|
-
|
|
17391
|
-
|
|
17392
|
-
|
|
17393
|
-
|
|
17394
|
-
|
|
17395
|
-
|
|
17396
|
-
|
|
17397
|
-
|
|
17398
|
-
|
|
17399
|
-
|
|
17400
|
-
|
|
17401
|
-
|
|
17402
|
-
|
|
17403
|
-
|
|
17404
|
-
|
|
17405
|
-
|
|
17406
|
-
|
|
17407
|
-
|
|
17408
|
-
|
|
17409
|
-
|
|
17410
|
-
|
|
17411
|
-
|
|
17412
|
-
|
|
17413
|
-
|
|
17414
|
-
|
|
17415
|
-
|
|
17416
|
-
|
|
17417
|
-
|
|
17418
|
-
|
|
17419
|
-
|
|
17420
|
-
|
|
17381
|
+
let result = true;
|
|
17382
|
+
if (valid.validator !== "required" || includeRequired) {
|
|
17383
|
+
switch (valid.validator) {
|
|
17384
|
+
case "required":
|
|
17385
|
+
result = validations.required(value);
|
|
17386
|
+
break;
|
|
17387
|
+
case "isEmail":
|
|
17388
|
+
result = validations.isEmail(value);
|
|
17389
|
+
break;
|
|
17390
|
+
case "isEmpty":
|
|
17391
|
+
result = validations.isEmpty(value);
|
|
17392
|
+
break;
|
|
17393
|
+
case "allowedExtensions":
|
|
17394
|
+
result = validations.allowedExtensions(value, valid.fileTypes);
|
|
17395
|
+
break;
|
|
17396
|
+
case "isFile":
|
|
17397
|
+
result = validations.isFile(value);
|
|
17398
|
+
break;
|
|
17399
|
+
case "isFloat":
|
|
17400
|
+
result = validations.isFloat(value);
|
|
17401
|
+
break;
|
|
17402
|
+
case "isNumber":
|
|
17403
|
+
result = validations.isNumber(value);
|
|
17404
|
+
break;
|
|
17405
|
+
case "isPositive":
|
|
17406
|
+
result = validations.isPositive(value);
|
|
17407
|
+
break;
|
|
17408
|
+
case "isString":
|
|
17409
|
+
result = validations.isString(value);
|
|
17410
|
+
break;
|
|
17411
|
+
case "matchRegexp":
|
|
17412
|
+
result = validations.matchRegexp(value, valid.regexp);
|
|
17413
|
+
break;
|
|
17414
|
+
case "maxFileSize":
|
|
17415
|
+
result = validations.maxFileSize(value, valid.max);
|
|
17416
|
+
break;
|
|
17417
|
+
case "maxFloat":
|
|
17418
|
+
result = validations.maxFloat(value, valid.max);
|
|
17419
|
+
break;
|
|
17420
|
+
case "maxNumber":
|
|
17421
|
+
result = validations.maxNumber(value, valid.max);
|
|
17422
|
+
break;
|
|
17423
|
+
case "maxStringLength":
|
|
17424
|
+
result = validations.maxStringLength(value, valid.max);
|
|
17425
|
+
break;
|
|
17426
|
+
case "minFloat":
|
|
17427
|
+
result = validations.minFloat(value, valid.min);
|
|
17428
|
+
break;
|
|
17429
|
+
case "minNumber":
|
|
17430
|
+
result = validations.minNumber(value, valid.min);
|
|
17431
|
+
break;
|
|
17432
|
+
case "minStringLength":
|
|
17433
|
+
result = validations.minStringLength(value, valid.min);
|
|
17434
|
+
break;
|
|
17435
|
+
case "trim":
|
|
17436
|
+
result = validations.trim(value);
|
|
17437
|
+
break;
|
|
17438
|
+
default:
|
|
17439
|
+
result = true;
|
|
17440
|
+
break;
|
|
17441
|
+
}
|
|
17421
17442
|
}
|
|
17443
|
+
return result;
|
|
17422
17444
|
};
|
|
17423
|
-
childs = [];
|
|
17424
|
-
errors = [];
|
|
17425
|
-
instantValidate = this.props.instantValidate !== void 0 ? this.props.instantValidate : true;
|
|
17426
|
-
debounceTime = this.props.debounceTime;
|
|
17427
17445
|
getFormHelpers = () => ({
|
|
17428
17446
|
form: {
|
|
17429
17447
|
attachToForm: this.attachToForm,
|
|
17430
|
-
debounceTime: this.props.debounceTime,
|
|
17431
17448
|
detachFromForm: this.detachFromForm,
|
|
17432
|
-
instantValidate: this.
|
|
17449
|
+
instantValidate: this.instantValidate,
|
|
17450
|
+
debounceTime: this.debounceTime
|
|
17433
17451
|
}
|
|
17434
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;
|
|
17435
17457
|
attachToForm = (component) => {
|
|
17436
17458
|
if (this.childs.indexOf(component) === -1) {
|
|
17437
17459
|
this.childs.push(component);
|
|
@@ -17451,7 +17473,9 @@ var ValidatorForm = class extends React61.Component {
|
|
|
17451
17473
|
this.errors = [];
|
|
17452
17474
|
this.walk(this.childs).then((result) => {
|
|
17453
17475
|
if (this.errors.length) {
|
|
17454
|
-
this.props.onError
|
|
17476
|
+
if (this.props.onError != void 0) {
|
|
17477
|
+
this.props.onError(this.errors);
|
|
17478
|
+
}
|
|
17455
17479
|
}
|
|
17456
17480
|
if (result) {
|
|
17457
17481
|
this.props.onSubmit();
|
|
@@ -17561,21 +17585,6 @@ var debounce2 = (func, wait, immediate) => {
|
|
|
17561
17585
|
|
|
17562
17586
|
// src/core/validator/ValidatorComponent.tsx
|
|
17563
17587
|
var ValidatorComponent = class extends React62.Component {
|
|
17564
|
-
renderValidatorComponent() {
|
|
17565
|
-
throw new Error("Method not implemented.");
|
|
17566
|
-
}
|
|
17567
|
-
form;
|
|
17568
|
-
debounceTime;
|
|
17569
|
-
validateDebounced;
|
|
17570
|
-
constructor(props) {
|
|
17571
|
-
super(props);
|
|
17572
|
-
this.state = {
|
|
17573
|
-
isValid: true,
|
|
17574
|
-
value: this.props.value,
|
|
17575
|
-
errorMessages: this.props.errorMessages,
|
|
17576
|
-
validators: this.props.validators
|
|
17577
|
-
};
|
|
17578
|
-
}
|
|
17579
17588
|
getSnapshotBeforeUpdate(nextProps, prevState) {
|
|
17580
17589
|
if (nextProps.validators && nextProps.errorMessages && (prevState.validators !== nextProps.validators || prevState.errorMessages !== nextProps.errorMessages)) {
|
|
17581
17590
|
return {
|
|
@@ -17588,17 +17597,15 @@ var ValidatorComponent = class extends React62.Component {
|
|
|
17588
17597
|
value: nextProps.value
|
|
17589
17598
|
};
|
|
17590
17599
|
}
|
|
17591
|
-
|
|
17592
|
-
|
|
17600
|
+
state = {
|
|
17601
|
+
isValid: true,
|
|
17602
|
+
value: this.props.value,
|
|
17603
|
+
errorMessages: this.props.errorMessages,
|
|
17604
|
+
validators: this.props.validators
|
|
17605
|
+
};
|
|
17593
17606
|
componentDidMount() {
|
|
17594
17607
|
this.configure();
|
|
17595
17608
|
}
|
|
17596
|
-
configure = () => {
|
|
17597
|
-
this.form.attachToForm(this);
|
|
17598
|
-
this.instantValidate = this.form.instantValidate;
|
|
17599
|
-
this.debounceTime = this.form.debounceTime;
|
|
17600
|
-
this.validateDebounced = debounce2(this.validate, this.debounceTime);
|
|
17601
|
-
};
|
|
17602
17609
|
shouldComponentUpdate(nextProps, nextState) {
|
|
17603
17610
|
return this.state !== nextState || this.props !== nextProps;
|
|
17604
17611
|
}
|
|
@@ -17617,41 +17624,57 @@ var ValidatorComponent = class extends React62.Component {
|
|
|
17617
17624
|
getErrorMessage = () => {
|
|
17618
17625
|
const { errorMessages } = this.state;
|
|
17619
17626
|
const type = typeof errorMessages;
|
|
17620
|
-
if (
|
|
17621
|
-
|
|
17622
|
-
|
|
17623
|
-
if (
|
|
17624
|
-
|
|
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
|
+
}
|
|
17625
17634
|
}
|
|
17626
17635
|
}
|
|
17627
17636
|
return true;
|
|
17628
17637
|
};
|
|
17629
|
-
|
|
17630
|
-
|
|
17631
|
-
|
|
17632
|
-
|
|
17633
|
-
|
|
17634
|
-
|
|
17635
|
-
|
|
17636
|
-
|
|
17637
|
-
|
|
17638
|
-
|
|
17639
|
-
|
|
17640
|
-
|
|
17641
|
-
|
|
17642
|
-
|
|
17643
|
-
|
|
17644
|
-
|
|
17645
|
-
|
|
17646
|
-
|
|
17647
|
-
|
|
17648
|
-
|
|
17649
|
-
|
|
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
|
+
};
|
|
17646
|
+
validate = async (value, includeRequired = false, dryRun = false) => {
|
|
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;
|
|
17650
17672
|
});
|
|
17673
|
+
} else {
|
|
17674
|
+
return true;
|
|
17651
17675
|
}
|
|
17652
|
-
return valid;
|
|
17653
17676
|
};
|
|
17654
|
-
isValid = () => this.state.isValid === void 0 ?
|
|
17677
|
+
isValid = () => this.state.isValid === void 0 ? true : this.state.isValid;
|
|
17655
17678
|
makeInvalid = () => {
|
|
17656
17679
|
this.setState({ isValid: false });
|
|
17657
17680
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-mui-form-validator",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"description": "Validator for forms designed with material-ui components.",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"types": "lib/index.d.ts",
|
|
7
5
|
"scripts": {
|
|
8
6
|
"prod": "rimraf ./lib && tsup src/index.ts --dts --outDir=lib",
|
|
7
|
+
"start": "react-scripts start",
|
|
9
8
|
"test": "jest",
|
|
10
9
|
"test:watch": "jest --watch"
|
|
11
10
|
},
|
|
@@ -39,12 +38,26 @@
|
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
40
|
"@mui/material": "^5.14.16",
|
|
42
|
-
"@types/
|
|
41
|
+
"@types/node": "^20.8.10",
|
|
42
|
+
"@types/react": "^18.2.34",
|
|
43
43
|
"@types/react-dom": "^18.2.14",
|
|
44
44
|
"@types/react-lifecycles-compat": "^3.0.3",
|
|
45
45
|
"mui-tel-input": "4.0.1",
|
|
46
46
|
"rimraf": "^5.0.5",
|
|
47
47
|
"tsup": "^7.2.0",
|
|
48
|
-
"
|
|
48
|
+
"react-scripts": "5.0.1",
|
|
49
|
+
"typescript": "^4.9.5"
|
|
50
|
+
},
|
|
51
|
+
"browserslist": {
|
|
52
|
+
"production": [
|
|
53
|
+
">0.2%",
|
|
54
|
+
"not dead",
|
|
55
|
+
"not op_mini all"
|
|
56
|
+
],
|
|
57
|
+
"development": [
|
|
58
|
+
"last 1 chrome version",
|
|
59
|
+
"last 1 firefox version",
|
|
60
|
+
"last 1 safari version"
|
|
61
|
+
]
|
|
49
62
|
}
|
|
50
63
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
3
4
|
"module": "ESNext",
|
|
4
5
|
"target": "ESNext",
|
|
5
6
|
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
"allowSyntheticDefaultImports": true,
|
|
14
15
|
"noFallthroughCasesInSwitch": true,
|
|
15
16
|
|
|
16
|
-
"outDir": "lib",
|
|
17
|
+
//"outDir": "lib",
|
|
17
18
|
"declaration": true,
|
|
18
19
|
"moduleResolution": "node",
|
|
19
20
|
"resolveJsonModule": true,
|