@nethru/ui 2.1.26 → 2.1.28
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/base/TextField.js +16 -15
- package/package.json +1 -1
package/base/TextField.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useCallback, useState } from "react";
|
|
1
|
+
import { forwardRef, useCallback, useEffect, useState } from "react";
|
|
2
2
|
import MuiTextField from "@mui/material/TextField";
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
const validateRule = process.env.REACT_APP_VALIDATE_RULE;
|
|
@@ -6,6 +6,7 @@ const validateMessage = process.env.REACT_APP_VALIDATE_MESSAGE;
|
|
|
6
6
|
// eslint-disable-next-line
|
|
7
7
|
const validate = validateRule ? new Function("value", validateRule) : null;
|
|
8
8
|
const TextField = /*#__PURE__*/forwardRef((props, ref) => {
|
|
9
|
+
const [modified, setModified] = useState(false);
|
|
9
10
|
const [error, setError] = useState(false);
|
|
10
11
|
const [helperText, setHelperText] = useState('');
|
|
11
12
|
const handleChange = useCallback(event => {
|
|
@@ -17,18 +18,21 @@ const TextField = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
17
18
|
setError(false);
|
|
18
19
|
setHelperText('');
|
|
19
20
|
}
|
|
20
|
-
if (props.formik) {
|
|
21
|
-
const {
|
|
22
|
-
setFieldError,
|
|
23
|
-
validateForm
|
|
24
|
-
} = props.formik;
|
|
25
|
-
validateForm().then(errors => {
|
|
26
|
-
if (isEmptyObject(errors)) setFieldError(props.name, helperText);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
21
|
}
|
|
22
|
+
setModified(true);
|
|
30
23
|
if (props.onChange) props.onChange(event);
|
|
31
|
-
}, [props
|
|
24
|
+
}, [props]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!validate || !props.formik || !modified) return;
|
|
27
|
+
const {
|
|
28
|
+
setFieldError,
|
|
29
|
+
validateForm
|
|
30
|
+
} = props.formik;
|
|
31
|
+
validateForm().then(errors => {
|
|
32
|
+
if (!errors[props.name]) setFieldError(props.name, error ? helperText : undefined);
|
|
33
|
+
});
|
|
34
|
+
// eslint-disable-next-line
|
|
35
|
+
}, [error]);
|
|
32
36
|
return /*#__PURE__*/_jsx(MuiTextField, {
|
|
33
37
|
ref: ref,
|
|
34
38
|
...props,
|
|
@@ -37,7 +41,4 @@ const TextField = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
37
41
|
onChange: handleChange
|
|
38
42
|
});
|
|
39
43
|
});
|
|
40
|
-
export default TextField;
|
|
41
|
-
function isEmptyObject(obj) {
|
|
42
|
-
return obj && Object.keys(obj).length === 0;
|
|
43
|
-
}
|
|
44
|
+
export default TextField;
|