react-mui-form-validator 1.5.0 → 1.5.2
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/Readme.md +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +89 -71
- package/package.json +3 -2
package/Readme.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ interface ValidatorFormProps {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
declare class ValidatorForm extends React$1.Component<ValidatorFormProps> {
|
|
96
|
-
static getValidator: (value: any, validator: Validator) => boolean;
|
|
96
|
+
static getValidator: (value: any, validator: Validator, includeRequired: boolean) => boolean;
|
|
97
97
|
childs: any[];
|
|
98
98
|
errors: any[];
|
|
99
99
|
instantValidate: boolean;
|
|
@@ -144,7 +144,7 @@ declare class ValidatorComponent extends React$1.Component<MuiTextFieldProps & V
|
|
|
144
144
|
componentDidUpdate(prevProps: MuiTextFieldProps, prevState: ValidatorComponentState): void;
|
|
145
145
|
componentWillUnmount(): void;
|
|
146
146
|
getErrorMessage: () => string | boolean | string[];
|
|
147
|
-
validate: (value: any, dryRun?: boolean) => Promise<boolean>;
|
|
147
|
+
validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>;
|
|
148
148
|
isValid: () => boolean;
|
|
149
149
|
makeInvalid: () => void;
|
|
150
150
|
makeValid: () => void;
|
package/lib/index.js
CHANGED
|
@@ -17377,48 +17377,71 @@ var ValidationRules_default = validations;
|
|
|
17377
17377
|
// src/core/validator/ValidatorForm.tsx
|
|
17378
17378
|
var FormContext = React61.createContext("form");
|
|
17379
17379
|
var ValidatorForm = class extends React61.Component {
|
|
17380
|
-
static getValidator = (value, validator2) => {
|
|
17380
|
+
static getValidator = (value, validator2, includeRequired) => {
|
|
17381
17381
|
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
|
-
|
|
17382
|
+
let result = true;
|
|
17383
|
+
if (valid.validator !== "required" || includeRequired) {
|
|
17384
|
+
switch (valid.validator) {
|
|
17385
|
+
case "required":
|
|
17386
|
+
result = ValidationRules_default.isEmpty(value);
|
|
17387
|
+
break;
|
|
17388
|
+
case "isEmail":
|
|
17389
|
+
result = ValidationRules_default.isEmail(value);
|
|
17390
|
+
break;
|
|
17391
|
+
case "isEmpty":
|
|
17392
|
+
result = ValidationRules_default.isEmpty(value);
|
|
17393
|
+
break;
|
|
17394
|
+
case "allowedExtensions":
|
|
17395
|
+
result = ValidationRules_default.allowedExtensions(value, valid.fileTypes);
|
|
17396
|
+
break;
|
|
17397
|
+
case "isFile":
|
|
17398
|
+
result = ValidationRules_default.isFile(value);
|
|
17399
|
+
break;
|
|
17400
|
+
case "isFloat":
|
|
17401
|
+
result = ValidationRules_default.isFloat(value);
|
|
17402
|
+
break;
|
|
17403
|
+
case "isNumber":
|
|
17404
|
+
result = ValidationRules_default.isNumber(value);
|
|
17405
|
+
break;
|
|
17406
|
+
case "isPositive":
|
|
17407
|
+
result = ValidationRules_default.isPositive(value);
|
|
17408
|
+
break;
|
|
17409
|
+
case "isString":
|
|
17410
|
+
result = ValidationRules_default.isString(value);
|
|
17411
|
+
break;
|
|
17412
|
+
case "matchRegexp":
|
|
17413
|
+
result = ValidationRules_default.matchRegexp(value, valid.regexp);
|
|
17414
|
+
break;
|
|
17415
|
+
case "maxFileSize":
|
|
17416
|
+
result = ValidationRules_default.maxFileSize(value, valid.max);
|
|
17417
|
+
break;
|
|
17418
|
+
case "maxFloat":
|
|
17419
|
+
result = ValidationRules_default.maxFloat(value, valid.max);
|
|
17420
|
+
break;
|
|
17421
|
+
case "maxNumber":
|
|
17422
|
+
result = ValidationRules_default.maxNumber(value, valid.max);
|
|
17423
|
+
break;
|
|
17424
|
+
case "maxStringLength":
|
|
17425
|
+
result = ValidationRules_default.maxStringLength(value, valid.max);
|
|
17426
|
+
break;
|
|
17427
|
+
case "minFloat":
|
|
17428
|
+
result = ValidationRules_default.minFloat(value, valid.min);
|
|
17429
|
+
break;
|
|
17430
|
+
case "minNumber":
|
|
17431
|
+
result = ValidationRules_default.minNumber(value, valid.min);
|
|
17432
|
+
break;
|
|
17433
|
+
case "minStringLength":
|
|
17434
|
+
result = ValidationRules_default.minStringLength(value, valid.min);
|
|
17435
|
+
break;
|
|
17436
|
+
case "trim":
|
|
17437
|
+
result = ValidationRules_default.trim(value);
|
|
17438
|
+
break;
|
|
17439
|
+
default:
|
|
17440
|
+
result = true;
|
|
17441
|
+
break;
|
|
17442
|
+
}
|
|
17421
17443
|
}
|
|
17444
|
+
return result;
|
|
17422
17445
|
};
|
|
17423
17446
|
childs = [];
|
|
17424
17447
|
errors = [];
|
|
@@ -17617,42 +17640,37 @@ var ValidatorComponent = class extends React62.Component {
|
|
|
17617
17640
|
getErrorMessage = () => {
|
|
17618
17641
|
const { errorMessages } = this.state;
|
|
17619
17642
|
const type = typeof errorMessages;
|
|
17620
|
-
if (
|
|
17621
|
-
|
|
17622
|
-
|
|
17623
|
-
|
|
17624
|
-
|
|
17625
|
-
return errorMessages[this.invalid[0]];
|
|
17626
|
-
}
|
|
17643
|
+
if (type === "string") {
|
|
17644
|
+
return errorMessages;
|
|
17645
|
+
} else if (type === "object") {
|
|
17646
|
+
if (this.invalid.length > 0) {
|
|
17647
|
+
return errorMessages[this.invalid[0]];
|
|
17627
17648
|
}
|
|
17628
17649
|
}
|
|
17629
17650
|
return true;
|
|
17630
17651
|
};
|
|
17631
|
-
validate = async (value, dryRun = false) => {
|
|
17632
|
-
|
|
17633
|
-
|
|
17634
|
-
|
|
17635
|
-
|
|
17636
|
-
|
|
17637
|
-
|
|
17638
|
-
|
|
17639
|
-
|
|
17640
|
-
|
|
17641
|
-
|
|
17642
|
-
|
|
17643
|
-
|
|
17644
|
-
valid = false;
|
|
17645
|
-
this.invalid.push(key);
|
|
17646
|
-
}
|
|
17647
|
-
});
|
|
17648
|
-
if (!dryRun) {
|
|
17649
|
-
this.setState({ isValid: valid }, () => {
|
|
17650
|
-
if (this.props.validatorListener)
|
|
17651
|
-
this.props.validatorListener(
|
|
17652
|
-
this.state.isValid === void 0 ? false : this.state.isValid
|
|
17653
|
-
);
|
|
17654
|
-
});
|
|
17652
|
+
validate = async (value, includeRequired = false, dryRun = false) => {
|
|
17653
|
+
const validations2 = Promise.all(
|
|
17654
|
+
this.state.validators.map(
|
|
17655
|
+
(validator2) => ValidatorForm_default.getValidator(value, validator2, includeRequired)
|
|
17656
|
+
)
|
|
17657
|
+
);
|
|
17658
|
+
const results = await validations2;
|
|
17659
|
+
this.invalid = [];
|
|
17660
|
+
let valid = true;
|
|
17661
|
+
results.forEach((result, key) => {
|
|
17662
|
+
if (!result) {
|
|
17663
|
+
valid = false;
|
|
17664
|
+
this.invalid.push(key);
|
|
17655
17665
|
}
|
|
17666
|
+
});
|
|
17667
|
+
if (!dryRun) {
|
|
17668
|
+
this.setState({ isValid: valid }, () => {
|
|
17669
|
+
if (this.props.validatorListener)
|
|
17670
|
+
this.props.validatorListener(
|
|
17671
|
+
this.state.isValid === void 0 ? false : this.state.isValid
|
|
17672
|
+
);
|
|
17673
|
+
});
|
|
17656
17674
|
}
|
|
17657
17675
|
return valid;
|
|
17658
17676
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-mui-form-validator",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Validator for forms designed with material-ui components.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@mui/material": "^5.14.16",
|
|
42
|
-
"@types/
|
|
42
|
+
"@types/node": "^20.8.10",
|
|
43
|
+
"@types/react": "^18.2.34",
|
|
43
44
|
"@types/react-dom": "^18.2.14",
|
|
44
45
|
"@types/react-lifecycles-compat": "^3.0.3",
|
|
45
46
|
"mui-tel-input": "4.0.1",
|