react-mui-form-validator 1.7.2 → 1.7.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.cjs +18 -15
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +21 -8
- package/lib/index.d.ts +21 -8
- package/lib/index.js +18 -15
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import * as React$1 from 'react';
|
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
import { FilledTextFieldProps, OutlinedTextFieldProps, StandardTextFieldProps, BoxProps } from '@mui/material';
|
|
4
4
|
import { MuiTelInputInfo } from 'mui-tel-input';
|
|
5
|
+
import { TextFieldProps } from '@mui/material/TextField';
|
|
5
6
|
|
|
6
7
|
interface required {
|
|
7
8
|
validator: "required";
|
|
@@ -106,8 +107,8 @@ declare class ValidatorForm extends React$1.Component<ValidatorFormProps & BoxPr
|
|
|
106
107
|
static getValidator: (validator: Validator, value: any, includeRequired: boolean) => boolean;
|
|
107
108
|
childs: any[];
|
|
108
109
|
errors: any[];
|
|
109
|
-
instantValidate: boolean;
|
|
110
|
-
debounceTime: number;
|
|
110
|
+
get instantValidate(): boolean;
|
|
111
|
+
get debounceTime(): number;
|
|
111
112
|
getFormHelpers: () => FormContextValue;
|
|
112
113
|
attachToForm: (component: any) => void;
|
|
113
114
|
detachFromForm: (component: any) => void;
|
|
@@ -120,20 +121,24 @@ declare class ValidatorForm extends React$1.Component<ValidatorFormProps & BoxPr
|
|
|
120
121
|
render(): React$1.JSX.Element;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
type DebouncedValidate = {
|
|
125
|
+
(value: any, includeRequired?: boolean, dryRun?: boolean): void;
|
|
126
|
+
cancel?: () => void;
|
|
127
|
+
};
|
|
128
|
+
declare class ValidatorComponent<P extends ValidatorComponentProps = ValidatorComponentProps> extends React$1.Component<P, ValidatorComponentState> {
|
|
124
129
|
static contextType: React$1.Context<FormContextValue>;
|
|
125
130
|
context: React$1.ContextType<typeof FormContext>;
|
|
126
|
-
validateDebounced:
|
|
127
|
-
form: FormContextValue["form"];
|
|
131
|
+
validateDebounced: DebouncedValidate | null;
|
|
132
|
+
form: NonNullable<FormContextValue["form"]> | null;
|
|
128
133
|
debounceTime: number;
|
|
129
134
|
instantValidate: boolean;
|
|
130
135
|
invalid: number[];
|
|
131
136
|
state: ValidatorComponentState;
|
|
132
137
|
renderValidatorComponent(): React$1.ReactNode;
|
|
133
138
|
componentDidMount(): void;
|
|
134
|
-
componentDidUpdate(prevProps:
|
|
139
|
+
componentDidUpdate(prevProps: P): void;
|
|
135
140
|
componentWillUnmount(): void;
|
|
136
|
-
shouldComponentUpdate(nextProps:
|
|
141
|
+
shouldComponentUpdate(nextProps: P, nextState: ValidatorComponentState): boolean;
|
|
137
142
|
configure: () => void;
|
|
138
143
|
getErrorMessage: () => string | boolean;
|
|
139
144
|
validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>;
|
|
@@ -148,7 +153,15 @@ declare class MuiSelect extends ValidatorComponent {
|
|
|
148
153
|
renderValidatorComponent(): React$1.JSX.Element;
|
|
149
154
|
}
|
|
150
155
|
|
|
151
|
-
|
|
156
|
+
type MuiTextFieldProps = Omit<TextFieldProps, "value"> & {
|
|
157
|
+
value: unknown;
|
|
158
|
+
validators?: any[];
|
|
159
|
+
errorMessages?: string | string[];
|
|
160
|
+
validatorListener?: (isValid: boolean) => void;
|
|
161
|
+
withRequiredValidator?: boolean;
|
|
162
|
+
containerProps?: React__default.HTMLAttributes<HTMLDivElement>;
|
|
163
|
+
};
|
|
164
|
+
declare class MuiTextField extends ValidatorComponent<MuiTextFieldProps> {
|
|
152
165
|
renderValidatorComponent(): React__default.JSX.Element;
|
|
153
166
|
}
|
|
154
167
|
|
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as React$1 from 'react';
|
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
import { FilledTextFieldProps, OutlinedTextFieldProps, StandardTextFieldProps, BoxProps } from '@mui/material';
|
|
4
4
|
import { MuiTelInputInfo } from 'mui-tel-input';
|
|
5
|
+
import { TextFieldProps } from '@mui/material/TextField';
|
|
5
6
|
|
|
6
7
|
interface required {
|
|
7
8
|
validator: "required";
|
|
@@ -106,8 +107,8 @@ declare class ValidatorForm extends React$1.Component<ValidatorFormProps & BoxPr
|
|
|
106
107
|
static getValidator: (validator: Validator, value: any, includeRequired: boolean) => boolean;
|
|
107
108
|
childs: any[];
|
|
108
109
|
errors: any[];
|
|
109
|
-
instantValidate: boolean;
|
|
110
|
-
debounceTime: number;
|
|
110
|
+
get instantValidate(): boolean;
|
|
111
|
+
get debounceTime(): number;
|
|
111
112
|
getFormHelpers: () => FormContextValue;
|
|
112
113
|
attachToForm: (component: any) => void;
|
|
113
114
|
detachFromForm: (component: any) => void;
|
|
@@ -120,20 +121,24 @@ declare class ValidatorForm extends React$1.Component<ValidatorFormProps & BoxPr
|
|
|
120
121
|
render(): React$1.JSX.Element;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
type DebouncedValidate = {
|
|
125
|
+
(value: any, includeRequired?: boolean, dryRun?: boolean): void;
|
|
126
|
+
cancel?: () => void;
|
|
127
|
+
};
|
|
128
|
+
declare class ValidatorComponent<P extends ValidatorComponentProps = ValidatorComponentProps> extends React$1.Component<P, ValidatorComponentState> {
|
|
124
129
|
static contextType: React$1.Context<FormContextValue>;
|
|
125
130
|
context: React$1.ContextType<typeof FormContext>;
|
|
126
|
-
validateDebounced:
|
|
127
|
-
form: FormContextValue["form"];
|
|
131
|
+
validateDebounced: DebouncedValidate | null;
|
|
132
|
+
form: NonNullable<FormContextValue["form"]> | null;
|
|
128
133
|
debounceTime: number;
|
|
129
134
|
instantValidate: boolean;
|
|
130
135
|
invalid: number[];
|
|
131
136
|
state: ValidatorComponentState;
|
|
132
137
|
renderValidatorComponent(): React$1.ReactNode;
|
|
133
138
|
componentDidMount(): void;
|
|
134
|
-
componentDidUpdate(prevProps:
|
|
139
|
+
componentDidUpdate(prevProps: P): void;
|
|
135
140
|
componentWillUnmount(): void;
|
|
136
|
-
shouldComponentUpdate(nextProps:
|
|
141
|
+
shouldComponentUpdate(nextProps: P, nextState: ValidatorComponentState): boolean;
|
|
137
142
|
configure: () => void;
|
|
138
143
|
getErrorMessage: () => string | boolean;
|
|
139
144
|
validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>;
|
|
@@ -148,7 +153,15 @@ declare class MuiSelect extends ValidatorComponent {
|
|
|
148
153
|
renderValidatorComponent(): React$1.JSX.Element;
|
|
149
154
|
}
|
|
150
155
|
|
|
151
|
-
|
|
156
|
+
type MuiTextFieldProps = Omit<TextFieldProps, "value"> & {
|
|
157
|
+
value: unknown;
|
|
158
|
+
validators?: any[];
|
|
159
|
+
errorMessages?: string | string[];
|
|
160
|
+
validatorListener?: (isValid: boolean) => void;
|
|
161
|
+
withRequiredValidator?: boolean;
|
|
162
|
+
containerProps?: React__default.HTMLAttributes<HTMLDivElement>;
|
|
163
|
+
};
|
|
164
|
+
declare class MuiTextField extends ValidatorComponent<MuiTextFieldProps> {
|
|
152
165
|
renderValidatorComponent(): React__default.JSX.Element;
|
|
153
166
|
}
|
|
154
167
|
|
package/lib/index.js
CHANGED
|
@@ -20255,8 +20255,12 @@ var ValidatorForm = class extends React72.Component {
|
|
|
20255
20255
|
};
|
|
20256
20256
|
childs = [];
|
|
20257
20257
|
errors = [];
|
|
20258
|
-
|
|
20259
|
-
|
|
20258
|
+
get instantValidate() {
|
|
20259
|
+
return this.props.instantValidate !== void 0 ? this.props.instantValidate : true;
|
|
20260
|
+
}
|
|
20261
|
+
get debounceTime() {
|
|
20262
|
+
return this.props.debounceTime !== void 0 ? this.props.debounceTime : 0;
|
|
20263
|
+
}
|
|
20260
20264
|
getFormHelpers = () => ({
|
|
20261
20265
|
form: {
|
|
20262
20266
|
attachToForm: this.attachToForm,
|
|
@@ -20280,9 +20284,7 @@ var ValidatorForm = class extends React72.Component {
|
|
|
20280
20284
|
}
|
|
20281
20285
|
};
|
|
20282
20286
|
submit = (event) => {
|
|
20283
|
-
|
|
20284
|
-
event.preventDefault();
|
|
20285
|
-
}
|
|
20287
|
+
event.preventDefault();
|
|
20286
20288
|
this.errors = [];
|
|
20287
20289
|
this.walk(this.childs).then((result) => {
|
|
20288
20290
|
if (this.errors.length && this.props.onError) {
|
|
@@ -20310,7 +20312,7 @@ var ValidatorForm = class extends React72.Component {
|
|
|
20310
20312
|
checkInput = (input, dryRun) => {
|
|
20311
20313
|
return new Promise((resolve) => {
|
|
20312
20314
|
const validators = input?.props?.validators;
|
|
20313
|
-
if (!validators || !Array.isArray(validators)) {
|
|
20315
|
+
if (!validators || !Array.isArray(validators) || validators.length === 0) {
|
|
20314
20316
|
resolve(true);
|
|
20315
20317
|
return;
|
|
20316
20318
|
}
|
|
@@ -20417,9 +20419,7 @@ var ValidatorComponent = class extends React73.Component {
|
|
|
20417
20419
|
}
|
|
20418
20420
|
}
|
|
20419
20421
|
componentWillUnmount() {
|
|
20420
|
-
|
|
20421
|
-
this.form.detachFromForm(this);
|
|
20422
|
-
}
|
|
20422
|
+
this.form?.detachFromForm?.(this);
|
|
20423
20423
|
if (this.validateDebounced?.cancel) {
|
|
20424
20424
|
this.validateDebounced.cancel();
|
|
20425
20425
|
}
|
|
@@ -20429,9 +20429,9 @@ var ValidatorComponent = class extends React73.Component {
|
|
|
20429
20429
|
}
|
|
20430
20430
|
configure = () => {
|
|
20431
20431
|
const form = this.context?.form;
|
|
20432
|
-
if (!form) {
|
|
20432
|
+
if (!form?.attachToForm || !form?.detachFromForm) {
|
|
20433
20433
|
console.error(
|
|
20434
|
-
"MuiTextField debe estar dentro de <
|
|
20434
|
+
"MuiTextField debe estar dentro de tu <MuiForm> local. No mezcles este MuiTextField con MuiForm de react-mui-form-validator."
|
|
20435
20435
|
);
|
|
20436
20436
|
return;
|
|
20437
20437
|
}
|
|
@@ -20439,7 +20439,12 @@ var ValidatorComponent = class extends React73.Component {
|
|
|
20439
20439
|
this.form.attachToForm(this);
|
|
20440
20440
|
this.instantValidate = this.form.instantValidate;
|
|
20441
20441
|
this.debounceTime = this.form.debounceTime;
|
|
20442
|
-
this.validateDebounced = debounce2(
|
|
20442
|
+
this.validateDebounced = debounce2(
|
|
20443
|
+
(value, includeRequired, dryRun) => {
|
|
20444
|
+
void this.validate(value, includeRequired, dryRun);
|
|
20445
|
+
},
|
|
20446
|
+
this.debounceTime
|
|
20447
|
+
);
|
|
20443
20448
|
};
|
|
20444
20449
|
getErrorMessage = () => {
|
|
20445
20450
|
const { errorMessages } = this.state;
|
|
@@ -20474,9 +20479,7 @@ var ValidatorComponent = class extends React73.Component {
|
|
|
20474
20479
|
});
|
|
20475
20480
|
if (!dryRun) {
|
|
20476
20481
|
this.setState({ isValid: valid }, () => {
|
|
20477
|
-
|
|
20478
|
-
this.props.validatorListener(this.isValid());
|
|
20479
|
-
}
|
|
20482
|
+
this.props.validatorListener?.(this.isValid());
|
|
20480
20483
|
});
|
|
20481
20484
|
}
|
|
20482
20485
|
return valid;
|