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 CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  ## Validation component for material-ui forms
2
3
 
3
4
  [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/MIT)
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
- switch (valid.validator) {
17383
- case "required":
17384
- return ValidationRules_default.isEmpty(value);
17385
- case "isEmail":
17386
- return ValidationRules_default.isEmail(value);
17387
- case "isEmpty":
17388
- return ValidationRules_default.isEmpty(value);
17389
- case "allowedExtensions":
17390
- return ValidationRules_default.allowedExtensions(value, valid.fileTypes);
17391
- case "isFile":
17392
- return ValidationRules_default.isFile(value);
17393
- case "isFloat":
17394
- return ValidationRules_default.isFloat(value);
17395
- case "isNumber":
17396
- return ValidationRules_default.isNumber(value);
17397
- case "isPositive":
17398
- return ValidationRules_default.isPositive(value);
17399
- case "isString":
17400
- return ValidationRules_default.isString(value);
17401
- case "matchRegexp":
17402
- return ValidationRules_default.matchRegexp(value, valid.regexp);
17403
- case "maxFileSize":
17404
- return ValidationRules_default.maxFileSize(value, valid.max);
17405
- case "maxFloat":
17406
- return ValidationRules_default.maxFloat(value, valid.max);
17407
- case "maxNumber":
17408
- return ValidationRules_default.maxNumber(value, valid.max);
17409
- case "maxStringLength":
17410
- return ValidationRules_default.maxStringLength(value, valid.max);
17411
- case "minFloat":
17412
- return ValidationRules_default.minFloat(value, valid.min);
17413
- case "minNumber":
17414
- return ValidationRules_default.minNumber(value, valid.min);
17415
- case "minStringLength":
17416
- return ValidationRules_default.minStringLength(value, valid.min);
17417
- case "trim":
17418
- return ValidationRules_default.trim(value);
17419
- default:
17420
- return true;
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 (errorMessages) {
17621
- if (type === "string") {
17622
- return errorMessages;
17623
- } else if (type === "object") {
17624
- if (this.invalid.length > 0) {
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
- let valid = false;
17633
- if (this.state.validators) {
17634
- const validations2 = Promise.all(
17635
- this.state.validators.map(
17636
- (validator2) => ValidatorForm_default.getValidator(value, validator2)
17637
- )
17638
- );
17639
- const results = await validations2;
17640
- this.invalid = [];
17641
- valid = true;
17642
- results.forEach((result, key) => {
17643
- if (!result) {
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.0",
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/react": "^18.2.33",
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",