react-mui-form-validator 1.5.1 → 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/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 = [];
@@ -17626,10 +17649,10 @@ var ValidatorComponent = class extends React62.Component {
17626
17649
  }
17627
17650
  return true;
17628
17651
  };
17629
- validate = async (value, dryRun = false) => {
17652
+ validate = async (value, includeRequired = false, dryRun = false) => {
17630
17653
  const validations2 = Promise.all(
17631
17654
  this.state.validators.map(
17632
- (validator2) => ValidatorForm_default.getValidator(value, validator2)
17655
+ (validator2) => ValidatorForm_default.getValidator(value, validator2, includeRequired)
17633
17656
  )
17634
17657
  );
17635
17658
  const results = await validations2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-mui-form-validator",
3
- "version": "1.5.1",
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",