@bindu-dashing/dam-solution-v2 5.8.174 → 5.8.175
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.
|
@@ -31,21 +31,45 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
31
31
|
const [form] = Form.useForm();
|
|
32
32
|
const formValues = Form.useWatch([], form);
|
|
33
33
|
const [isFormValid, setIsFormValid] = useState(false);
|
|
34
|
+
const [disabledReason, setDisabledReason] = useState(null);
|
|
34
35
|
useEffect(() => {
|
|
35
36
|
const checkFormValidity = () => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
36
38
|
try {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
+
// Only check errors for main fields (name, placeholder, defaultValue)
|
|
40
|
+
const mainFieldNames = ["name", "placeholder", "defaultValue"];
|
|
41
|
+
const errors = form.getFieldsError(mainFieldNames);
|
|
42
|
+
const hasMainFieldErrors = errors.some((error) => { var _a; return ((_a = error.errors) === null || _a === void 0 ? void 0 : _a.length) > 0; });
|
|
39
43
|
// Get current form values
|
|
40
44
|
const values = form.getFieldsValue();
|
|
41
45
|
const nameFilled = !!(values.name && typeof values.name === 'string' && values.name.trim() !== '');
|
|
42
46
|
const placeholderFilled = !!(values.placeholder && typeof values.placeholder === 'string' && values.placeholder.trim() !== '');
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
const valid = nameFilled && placeholderFilled && !hasMainFieldErrors;
|
|
48
|
+
setIsFormValid(valid);
|
|
49
|
+
// Set reason for disabled state so user knows why
|
|
50
|
+
if (!valid) {
|
|
51
|
+
if (!nameFilled) {
|
|
52
|
+
setDisabledReason("Name is required");
|
|
53
|
+
}
|
|
54
|
+
else if (!placeholderFilled) {
|
|
55
|
+
setDisabledReason("Placeholder is required");
|
|
56
|
+
}
|
|
57
|
+
else if (hasMainFieldErrors) {
|
|
58
|
+
const firstError = errors.find((e) => { var _a; return ((_a = e.errors) === null || _a === void 0 ? void 0 : _a.length) > 0; });
|
|
59
|
+
const errorMsg = (_a = firstError === null || firstError === void 0 ? void 0 : firstError.errors) === null || _a === void 0 ? void 0 : _a[0];
|
|
60
|
+
setDisabledReason(errorMsg ? `Fix error: ${errorMsg}` : "Please fix the form errors above");
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
setDisabledReason(null);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
setDisabledReason(null);
|
|
68
|
+
}
|
|
46
69
|
}
|
|
47
70
|
catch (error) {
|
|
48
71
|
setIsFormValid(false);
|
|
72
|
+
setDisabledReason("Unable to validate form");
|
|
49
73
|
}
|
|
50
74
|
});
|
|
51
75
|
checkFormValidity();
|
|
@@ -165,14 +189,29 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
165
189
|
handleFormValuesChange();
|
|
166
190
|
// Check initial form validity after setting field values
|
|
167
191
|
setTimeout(() => {
|
|
168
|
-
|
|
169
|
-
const
|
|
192
|
+
var _a;
|
|
193
|
+
const mainFieldNames = ["name", "placeholder", "defaultValue"];
|
|
194
|
+
const errors = form.getFieldsError(mainFieldNames);
|
|
195
|
+
const hasMainFieldErrors = errors.some((error) => error.errors && error.errors.length > 0);
|
|
170
196
|
const values = form.getFieldsValue();
|
|
171
197
|
const nameFilled = !!(values.name && typeof values.name === 'string' && values.name.trim() !== '');
|
|
172
198
|
const placeholderFilled = !!(values.placeholder && typeof values.placeholder === 'string' && values.placeholder.trim() !== '');
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
199
|
+
const valid = nameFilled && placeholderFilled && !hasMainFieldErrors;
|
|
200
|
+
setIsFormValid(valid);
|
|
201
|
+
if (!valid) {
|
|
202
|
+
if (!nameFilled)
|
|
203
|
+
setDisabledReason("Name is required");
|
|
204
|
+
else if (!placeholderFilled)
|
|
205
|
+
setDisabledReason("Placeholder is required");
|
|
206
|
+
else if (hasMainFieldErrors) {
|
|
207
|
+
const firstError = errors.find((e) => { var _a; return ((_a = e.errors) === null || _a === void 0 ? void 0 : _a.length) > 0; });
|
|
208
|
+
setDisabledReason(((_a = firstError === null || firstError === void 0 ? void 0 : firstError.errors) === null || _a === void 0 ? void 0 : _a[0]) ? `Fix error: ${firstError.errors[0]}` : "Please fix the form errors above");
|
|
209
|
+
}
|
|
210
|
+
else
|
|
211
|
+
setDisabledReason(null);
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
setDisabledReason(null);
|
|
176
215
|
}, 100);
|
|
177
216
|
}, [field, form]);
|
|
178
217
|
// Update defaultValueInput whenever form values change
|
|
@@ -219,26 +258,21 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
219
258
|
},
|
|
220
259
|
});
|
|
221
260
|
}
|
|
222
|
-
// Rule for NUMBERS:
|
|
261
|
+
// Rule for NUMBERS: reject strings - only accept number type
|
|
223
262
|
if (defaultName === InputTypes.NUMBERS) {
|
|
224
263
|
rules.push({
|
|
225
264
|
validator: (_, value) => {
|
|
226
265
|
if (value === undefined || value === null || value === "") {
|
|
227
266
|
return Promise.resolve();
|
|
228
267
|
}
|
|
229
|
-
//
|
|
230
|
-
if (typeof value
|
|
231
|
-
return Promise.
|
|
268
|
+
// Only accept actual number type - reject all strings
|
|
269
|
+
if (typeof value !== "number") {
|
|
270
|
+
return Promise.reject("Default value must be a number, not text");
|
|
232
271
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const parsed = Number(value);
|
|
236
|
-
const trimmedValue = value.trim();
|
|
237
|
-
if (!isNaN(parsed) && isFinite(parsed) && trimmedValue !== "") {
|
|
238
|
-
return Promise.resolve();
|
|
239
|
-
}
|
|
272
|
+
if (isNaN(value) || !isFinite(value)) {
|
|
273
|
+
return Promise.reject("Default value must be a valid number");
|
|
240
274
|
}
|
|
241
|
-
return Promise.
|
|
275
|
+
return Promise.resolve();
|
|
242
276
|
},
|
|
243
277
|
});
|
|
244
278
|
}
|
|
@@ -314,12 +348,12 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
314
348
|
InputTypes.TEAM,
|
|
315
349
|
InputTypes.CHECKBOX,
|
|
316
350
|
InputTypes.RADIO,
|
|
317
|
-
], get(currentInputType, "defaultName")) && (_jsx(OptionsField, { field: field, supportedTypes: get(currentInputType, "supportedTypes", []), currentInputType: currentInputType }))] })] }), _jsxs(Form.Item, { className: "md-lib-flex md-lib-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
351
|
+
], get(currentInputType, "defaultName")) && (_jsx(OptionsField, { field: field, supportedTypes: get(currentInputType, "supportedTypes", []), currentInputType: currentInputType }))] })] }), _jsxs(Form.Item, { className: "md-lib-flex md-lib-flex-col md-lib-items-end md-lib-absolute md-lib-bottom-0 md-lib-right-0 md-lib-pr-4 md-lib-pb-4", children: [disabledReason && (_jsxs("p", { className: "md-lib-text-sm md-lib-mb-2 md-lib-mr-2", style: { color: styles === null || styles === void 0 ? void 0 : styles.secondaryTextColor }, children: ["Update disabled: ", disabledReason] })), _jsxs("div", { className: "md-lib-flex md-lib-items-center", children: [_jsx(Button, { color: "primary", variant: "text", onClick: () => {
|
|
352
|
+
if (onCancel && index !== null) {
|
|
353
|
+
onCancel(index);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
setCurrentFieldIndex(null);
|
|
357
|
+
}
|
|
358
|
+
}, size: "large", children: "Cancel" }), _jsx(Button, { color: "primary", htmlType: "submit", className: "md-lib-ml-2 md-lib-border-primaryColor md-lib-text-primaryColor", size: "large", loading: loading, disabled: !isFormValid || loading, title: disabledReason || undefined, children: "Update" })] })] })] }) })] }));
|
|
325
359
|
}
|