@gustavo-valsechi/client 1.4.152 → 1.4.154
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.
|
@@ -47,9 +47,13 @@ function Form(props) {
|
|
|
47
47
|
const [submitting, setSubmitting] = (0, import_react.useState)(false);
|
|
48
48
|
const setSchema = () => {
|
|
49
49
|
const schema2 = {};
|
|
50
|
+
const validation = (data) => (data.validation || import_zod.z.string().optional()).transform((value) => value != null ? value : void 0);
|
|
50
51
|
import_lodash.default.forEach(props.inputs, (data) => {
|
|
51
|
-
if (
|
|
52
|
-
|
|
52
|
+
if (import_lodash.default.isArray(data)) {
|
|
53
|
+
import_lodash.default.forEach(data, (input) => schema2[input.name] = validation(input));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
schema2[data.name] = validation(data);
|
|
53
57
|
});
|
|
54
58
|
if (props.validation) return props.validation(import_zod.z.object(schema2));
|
|
55
59
|
return import_zod.z.object(schema2);
|
|
@@ -76,7 +80,10 @@ function Form(props) {
|
|
|
76
80
|
if (!props.defaultValues || !((_a = Object.keys(props.defaultValues || {})) == null ? void 0 : _a.length)) return;
|
|
77
81
|
const defaultValues = { ...props.defaultValues };
|
|
78
82
|
import_lodash.default.forEach(defaultValues, (value, key) => {
|
|
79
|
-
const input = import_lodash.default.find(props.inputs, (data) =>
|
|
83
|
+
const input = import_lodash.default.find(props.inputs, (data) => {
|
|
84
|
+
if (import_lodash.default.isArray(data)) return import_lodash.default.some(data, (input2) => input2.name === key);
|
|
85
|
+
return data.name === key;
|
|
86
|
+
});
|
|
80
87
|
if (!input) {
|
|
81
88
|
delete defaultValues[key];
|
|
82
89
|
return;
|
|
@@ -13,9 +13,13 @@ function Form(props) {
|
|
|
13
13
|
const [submitting, setSubmitting] = useState(false);
|
|
14
14
|
const setSchema = () => {
|
|
15
15
|
const schema2 = {};
|
|
16
|
+
const validation = (data) => (data.validation || z.string().optional()).transform((value) => value != null ? value : void 0);
|
|
16
17
|
_.forEach(props.inputs, (data) => {
|
|
17
|
-
if (
|
|
18
|
-
|
|
18
|
+
if (_.isArray(data)) {
|
|
19
|
+
_.forEach(data, (input) => schema2[input.name] = validation(input));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
schema2[data.name] = validation(data);
|
|
19
23
|
});
|
|
20
24
|
if (props.validation) return props.validation(z.object(schema2));
|
|
21
25
|
return z.object(schema2);
|
|
@@ -42,7 +46,10 @@ function Form(props) {
|
|
|
42
46
|
if (!props.defaultValues || !((_a = Object.keys(props.defaultValues || {})) == null ? void 0 : _a.length)) return;
|
|
43
47
|
const defaultValues = { ...props.defaultValues };
|
|
44
48
|
_.forEach(defaultValues, (value, key) => {
|
|
45
|
-
const input = _.find(props.inputs, (data) =>
|
|
49
|
+
const input = _.find(props.inputs, (data) => {
|
|
50
|
+
if (_.isArray(data)) return _.some(data, (input2) => input2.name === key);
|
|
51
|
+
return data.name === key;
|
|
52
|
+
});
|
|
46
53
|
if (!input) {
|
|
47
54
|
delete defaultValues[key];
|
|
48
55
|
return;
|
|
@@ -111,12 +111,12 @@ function InputSelect(props) {
|
|
|
111
111
|
"input",
|
|
112
112
|
{
|
|
113
113
|
...import_lodash.default.omit(props, ["className", "register", "mask", "setValue", "watch"]),
|
|
114
|
-
ref: inputRef,
|
|
115
114
|
type: "text",
|
|
116
115
|
maxLength: props.maxLength || 255,
|
|
117
116
|
value: focus ? filter : inputValue,
|
|
118
117
|
placeholder: import_lodash.default.isString(value) ? value : (value == null ? void 0 : value.textContent) || "",
|
|
119
118
|
...register,
|
|
119
|
+
ref: inputRef,
|
|
120
120
|
onBlur,
|
|
121
121
|
onFocus,
|
|
122
122
|
onChange,
|
|
@@ -78,12 +78,12 @@ function InputSelect(props) {
|
|
|
78
78
|
"input",
|
|
79
79
|
{
|
|
80
80
|
..._.omit(props, ["className", "register", "mask", "setValue", "watch"]),
|
|
81
|
-
ref: inputRef,
|
|
82
81
|
type: "text",
|
|
83
82
|
maxLength: props.maxLength || 255,
|
|
84
83
|
value: focus ? filter : inputValue,
|
|
85
84
|
placeholder: _.isString(value) ? value : (value == null ? void 0 : value.textContent) || "",
|
|
86
85
|
...register,
|
|
86
|
+
ref: inputRef,
|
|
87
87
|
onBlur,
|
|
88
88
|
onFocus,
|
|
89
89
|
onChange,
|