@wavemaker/react-runtime 11.14.2-rc.6311 → 12.0.0-next.28533
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/actions/base-action.js +5 -7
- package/actions/login-action.js +7 -8
- package/actions/logout-action.js +5 -7
- package/actions/navigation-action.js +32 -10
- package/actions/notification-action.js +22 -8
- package/actions/timer-action.js +13 -15
- package/actions/toast.js +4 -2
- package/actions/toast.service.js +1 -2
- package/components/advanced/carousel/index.js +1 -1
- package/components/advanced/carousel/template.js +1 -1
- package/components/basic/anchor/index.js +26 -9
- package/components/basic/html/index.js +115 -24
- package/components/basic/icon/index.js +2 -1
- package/components/basic/iframe/index.js +2 -1
- package/components/basic/label/index.js +12 -9
- package/components/basic/message/index.js +12 -3
- package/components/basic/picture/index.js +11 -4
- package/components/basic/progress-bar/index.js +1 -1
- package/components/basic/progress-circle/index.js +34 -28
- package/components/basic/progress-circle/props.js +10 -2
- package/components/basic/richtexteditor/index.js +95 -94
- package/components/basic/search/index.js +401 -156
- package/components/basic/search/providers.js +126 -61
- package/components/basic/spinner/index.js +2 -1
- package/components/basic/tree/index.js +34 -34
- package/components/basic/tree/utils.js +10 -4
- package/components/chart/components/barColumnChart/index.js +36 -33
- package/components/chart/components/bubbleChart/index.js +35 -25
- package/components/chart/components/chartLegend/utils.js +2 -1
- package/components/chart/components/cumulativeLineChart/index.js +30 -26
- package/components/chart/components/lineAreaChart/index.js +50 -32
- package/components/chart/components/pieDonutChart/index.js +13 -4
- package/components/chart/hooks/useXAxisConfig.js +15 -8
- package/components/chart/index.js +223 -53
- package/components/chart/utils.js +12 -1
- package/components/constants.js +5 -2
- package/components/container/accordion/accordion-pane/index.js +17 -12
- package/components/container/accordion/index.js +9 -4
- package/components/container/alignment-utils.js +56 -1
- package/components/container/index.js +49 -20
- package/components/container/panel/components/panel-header/index.js +3 -4
- package/components/container/panel/index.js +15 -10
- package/components/container/tabs/index.js +92 -14
- package/components/container/tabs/tab-pane/index.js +15 -8
- package/components/container/tabs/utils.js +51 -0
- package/components/container/wizard/components/StepComponents.js +2 -1
- package/components/container/wizard/components/WizardStep.js +2 -1
- package/components/container/wizard/index.js +64 -35
- package/components/container/wizard/utils.js +46 -1
- package/components/container/wizard/wizard-step/index.js +11 -1
- package/components/data/card/card-content/index.js +1 -1
- package/components/data/form/base-form/index.js +991 -180
- package/components/data/form/base-form/props.js +3 -1
- package/components/data/form/base-form/utils.js +159 -1
- package/components/data/form/dynamic-fields/constant.js +53 -0
- package/components/data/form/dynamic-fields/index.js +10 -45
- package/components/data/form/dynamic-fields/utils.js +37 -2
- package/components/data/form/form-action/index.js +5 -4
- package/components/data/form/form-context.js +5 -1
- package/components/data/form/form-controller/utils.js +84 -0
- package/components/data/form/form-controller/validation-contrustor.js +402 -189
- package/components/data/form/form-controller/withFormController.js +191 -52
- package/components/data/form/form-field/base-field.js +54 -33
- package/components/data/form/form-field/index.js +28 -5
- package/components/data/form/form-header/index.js +3 -4
- package/components/data/form/index.js +20 -1
- package/components/data/list/components/ListDND.js +2 -1
- package/components/data/list/components/ListItem.js +6 -2
- package/components/data/list/components/ListItemWithTemplate.js +46 -2
- package/components/data/list/components/ListItems.js +17 -26
- package/components/data/list/components/ListPagination.js +3 -3
- package/components/data/list/components/StandardListItems.js +3 -4
- package/components/data/list/hooks/useListEffects.js +55 -14
- package/components/data/list/hooks/useListEventHandlers.js +3 -1
- package/components/data/list/hooks/useListState.js +3 -1
- package/components/data/list/hooks/usePaginatedGroupedData.js +18 -5
- package/components/data/list/index.js +74 -55
- package/components/data/list/utils/list-helpers.js +73 -35
- package/components/data/list/utils/list-widget-methods.js +138 -95
- package/components/data/live-filter/index.js +26 -15
- package/components/data/live-form/index.js +23 -7
- package/components/data/live-form/props.js +1 -1
- package/components/data/pagination/components/BasicPagination.js +71 -16
- package/components/data/pagination/components/PageSizeSelector.js +8 -3
- package/components/data/pagination/components/TotalRecords.js +1 -5
- package/components/data/pagination/hooks/usePagination.js +349 -66
- package/components/data/pagination/index.js +137 -19
- package/components/data/table/components/AddNewRow.js +5 -1
- package/components/data/table/components/EditableCell.js +2 -2
- package/components/data/table/components/RowCells.js +64 -0
- package/components/data/table/components/RowExpansionButton.js +2 -2
- package/components/data/table/components/SummaryCell.js +111 -0
- package/components/data/table/components/SummaryRow.js +54 -0
- package/components/data/table/components/SummaryRowFooter.js +46 -0
- package/components/data/table/components/TableBody.js +61 -59
- package/components/data/table/components/TableDataRow.js +109 -0
- package/components/data/table/components/TableFilters.js +225 -121
- package/components/data/table/components/TableHeader.js +291 -23
- package/components/data/table/components/TablePanelHeading.js +139 -8
- package/components/data/table/components/index.js +22 -1
- package/components/data/table/hooks/use-edited-rows.js +141 -0
- package/components/data/table/hooks/useCellState.js +5 -12
- package/components/data/table/hooks/useFormWidget.js +58 -51
- package/components/data/table/hooks/usePaginationState.js +45 -24
- package/components/data/table/hooks/usePanelStructure.js +4 -4
- package/components/data/table/hooks/useRowHandlers.js +39 -5
- package/components/data/table/hooks/useRowSelection.js +244 -50
- package/components/data/table/hooks/useServerSideSorting.js +81 -37
- package/components/data/table/hooks/useTableColumns.js +211 -118
- package/components/data/table/hooks/useTableData.js +54 -9
- package/components/data/table/hooks/useTableEdit.js +272 -97
- package/components/data/table/hooks/useTableEffects.js +31 -13
- package/components/data/table/hooks/useTableFilter.js +1 -1
- package/components/data/table/hooks/useTableInitialization.js +23 -22
- package/components/data/table/hooks/useTableState.js +11 -5
- package/components/data/table/hooks/useTableStateManager.js +140 -65
- package/components/data/table/index.js +637 -274
- package/components/data/table/live-table/index.js +54 -22
- package/components/data/table/table-action/index.js +1 -1
- package/components/data/table/table-group/index.js +26 -0
- package/components/data/table/table-row-action/index.js +32 -18
- package/components/data/table/utils/buildSelectionColumns.js +12 -21
- package/components/data/table/utils/columnBuilder.js +29 -14
- package/components/data/table/utils/columnProxy.js +68 -1
- package/components/data/table/utils/constants.js +6 -2
- package/components/data/table/utils/crud-handlers.js +68 -63
- package/components/data/table/utils/groupHeaderUtils.js +102 -0
- package/components/data/table/utils/index.js +210 -21
- package/components/data/table/utils/renderDisplayCell.js +6 -6
- package/components/data/table/utils/selectionUtils.js +25 -26
- package/components/data/table/utils/validation.js +1 -0
- package/components/data/utils/filter-field-util.js +3 -3
- package/components/dialogs/alert-dialog/index.js +1 -1
- package/components/dialogs/confirm-dialog/index.js +1 -1
- package/components/dialogs/dialog/index.js +4 -1
- package/components/dialogs/dialog-content/index.js +3 -1
- package/components/dialogs/dialog-header/index.js +2 -2
- package/components/dialogs/iframe-dialog/index.js +11 -5
- package/components/dialogs/index.js +1 -1
- package/components/dialogs/login-dialog/index.js +1 -1
- package/components/dialogs/page-dialog/index.js +1 -1
- package/components/form/button/index.js +33 -7
- package/components/input/calendar/index.js +18 -6
- package/components/input/chips/index.js +99 -28
- package/components/input/chips/utils.js +34 -4
- package/components/input/color-picker/index.js +74 -25
- package/components/input/composite/index.js +3 -3
- package/components/input/currency/index.js +35 -49
- package/components/input/default/checkbox/index.js +23 -28
- package/components/input/default/checkboxset/index.js +38 -18
- package/components/input/default/checkboxset/utils.js +30 -0
- package/components/input/default/radioset/index.js +36 -39
- package/components/input/default/switch/index.js +30 -13
- package/components/input/epoch/date/index.js +130 -69
- package/components/input/epoch/date/utils.js +94 -1
- package/components/input/epoch/datetime/index.js +72 -22
- package/components/input/epoch/datetime/utils.js +49 -10
- package/components/input/epoch/time/index.js +68 -19
- package/components/input/epoch/time/utils.js +62 -14
- package/components/input/fileupload/Utils.js +12 -7
- package/components/input/fileupload/components/MultiUpload.js +2 -6
- package/components/input/fileupload/components/SingleUpload.js +3 -7
- package/components/input/fileupload/index.js +6 -10
- package/components/input/fileupload/useFileUpload.js +16 -5
- package/components/input/number/index.js +158 -43
- package/components/input/rating/index.js +90 -7
- package/components/input/select/index.js +147 -70
- package/components/input/slider/index.js +84 -26
- package/components/input/text/index.js +38 -18
- package/components/input/text/util.js +283 -130
- package/components/input/textarea/index.js +13 -10
- package/components/input/upload/index.js +124 -0
- package/components/input/upload/props.js +5 -0
- package/components/input/util/index.js +11 -0
- package/components/navbar/index.js +51 -3
- package/components/navbar/nav/index.js +46 -16
- package/components/navbar/nav-item/index.js +11 -5
- package/components/navigation/menu/components/ListItems.js +3 -0
- package/components/navigation/menu/constants.js +2 -1
- package/components/navigation/menu/hooks/useHoverState.hook.js +48 -0
- package/components/navigation/menu/hooks/useKeyboardMovements.hook.js +37 -0
- package/components/navigation/menu/hooks/useTransformedDataset.hook.js +15 -0
- package/components/navigation/menu/index.js +326 -188
- package/components/navigation/menu/utils/action-task.js +14 -0
- package/components/navigation/menu/utils/role-filter.js +76 -0
- package/components/navigation/popover/index.js +99 -26
- package/components/page/partial-container/index.js +34 -5
- package/components/prefab/index.js +2 -4
- package/context/PrefabContext.js +10 -6
- package/context/WidgetProvider.js +30 -31
- package/core/app.service.js +1 -1
- package/core/constants/events.js +57 -1
- package/core/dialog.service.js +1 -2
- package/core/event-notifier.js +1 -2
- package/core/formatter/array-formatters.js +33 -0
- package/core/formatter/date-formatters.js +2 -4
- package/core/formatter/index.js +2 -1
- package/core/formatter/number-formatters.js +5 -10
- package/core/formatter/security-formatters.js +2 -4
- package/core/formatter/string-formatters.js +3 -6
- package/core/proxy-service.js +84 -13
- package/core/script-registry.js +108 -48
- package/core/util/common.js +4 -4
- package/core/util/compare.js +30 -0
- package/core/util/dom.js +8 -8
- package/core/util/index.js +16 -6
- package/core/util/safe-is-equal.js +156 -0
- package/core/util/security.js +1 -2
- package/core/util/utils.js +16 -7
- package/higherOrder/BaseApp.js +108 -65
- package/higherOrder/BaseDateTime.js +31 -13
- package/higherOrder/BasePage.js +268 -144
- package/higherOrder/BasePartial.js +1 -1
- package/higherOrder/BasePrefab.js +33 -15
- package/higherOrder/DataNav.js +99 -16
- package/higherOrder/helper.js +5 -0
- package/higherOrder/withBaseWrapper.js +41 -28
- package/hooks/useAuth.js +11 -5
- package/hooks/useHttp.js +280 -94
- package/mui-config/theme-provider.js +1 -1
- package/mui-config/theme.js +1 -1
- package/package-lock.json +824 -724
- package/package.json +8 -8
- package/store/bindActions/i18nActions.js +18 -0
- package/store/index.js +3 -1
- package/store/slices/appConfigSlice.js +2 -2
- package/store/slices/authSlice.js +31 -28
- package/store/slices/i18nSlice.js +2 -2
- package/store/slices/navigationSlice.js +35 -0
- package/store/viewport.service.js +255 -0
- package/utils/attr.js +35 -0
- package/utils/dataset-util.js +1 -2
- package/utils/form-state.util.js +43 -12
- package/utils/form-utils.js +47 -2
- package/utils/format-util.js +28 -13
- package/utils/page-params-util.js +33 -1
- package/utils/state-persistance.js +72 -13
- package/utils/transformedDataset-utils.js +35 -24
- package/variables/base-variable.js +12 -14
- package/variables/crud-variable.js +225 -0
- package/variables/live-variable.js +56 -20
- package/variables/metadata.service.js +123 -0
- package/variables/model-variable.js +21 -15
- package/variables/service-variable.js +88 -83
|
@@ -16,10 +16,17 @@ var _clsx = _interopRequireDefault(require("clsx"));
|
|
|
16
16
|
var _reactHookForm = require("react-hook-form");
|
|
17
17
|
var _get = _interopRequireDefault(require("lodash-es/get"));
|
|
18
18
|
var _set = _interopRequireDefault(require("lodash-es/set"));
|
|
19
|
+
var _isEqual = _interopRequireDefault(require("lodash-es/isEqual"));
|
|
19
20
|
var _props = require("./props");
|
|
20
21
|
var _utils = require("./utils");
|
|
21
22
|
var _formContext = require("../form-context");
|
|
22
23
|
var _lodashEs = require("lodash-es");
|
|
24
|
+
var _utils2 = require("../../utils");
|
|
25
|
+
var _listHelpers = require("../../list/utils/list-helpers");
|
|
26
|
+
var _PrefabContext = require("../../../../context/PrefabContext");
|
|
27
|
+
var _events = require("../../../../core/constants/events");
|
|
28
|
+
var _merge = _interopRequireDefault(require("lodash-es/merge"));
|
|
29
|
+
var _formUtils = require("../../../../utils/form-utils");
|
|
23
30
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
|
|
24
31
|
var __jsx = _react["default"].createElement;
|
|
25
32
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -27,9 +34,20 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
27
34
|
var DEFAULT_CLASS = "panel app-panel app-form";
|
|
28
35
|
var BaseForm = function BaseForm(WrappedComponent) {
|
|
29
36
|
var ControlledForm = function ControlledForm(FormProps) {
|
|
30
|
-
var _props$
|
|
37
|
+
var _prefabContext$formAr, _props$listener, _props$listener2, _props$listener15;
|
|
31
38
|
// setting up default props for form
|
|
32
39
|
var props = _objectSpread(_objectSpread({}, _props.defaultProps), FormProps);
|
|
40
|
+
var parentFormRef = (0, _formContext.useFormRef)();
|
|
41
|
+
var formReff = (0, _react.useRef)(null);
|
|
42
|
+
|
|
43
|
+
// Get parent form from prefab context if available
|
|
44
|
+
var prefabContext = (0, _react.useContext)(_PrefabContext.PrefabContext);
|
|
45
|
+
var parentForm = props.parentForm || (prefabContext === null || prefabContext === void 0 ? void 0 : prefabContext.parentForm);
|
|
46
|
+
var isParentList = props.isParentList !== undefined ? props.isParentList : (prefabContext === null || prefabContext === void 0 ? void 0 : prefabContext.isParentList) || false;
|
|
47
|
+
var formArrayIndex = props.formArrayIndex !== undefined ? props.formArrayIndex : (_prefabContext$formAr = prefabContext === null || prefabContext === void 0 ? void 0 : prefabContext.formArrayIndex) !== null && _prefabContext$formAr !== void 0 ? _prefabContext$formAr : -1;
|
|
48
|
+
|
|
49
|
+
// For child forms, use childdatasetnode if provided, otherwise use form name as fallback
|
|
50
|
+
var effectiveChildDatasetNode = parentForm ? (prefabContext === null || prefabContext === void 0 ? void 0 : prefabContext.parentListName) || props.parentListName || props.childdatasetnode || props.name : undefined;
|
|
33
51
|
var isInsideWizard = props.isInsideWizard || false;
|
|
34
52
|
var formRef = (0, _react.useRef)(null);
|
|
35
53
|
var _useState = (0, _react.useState)({}),
|
|
@@ -38,26 +56,43 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
38
56
|
var _useState2 = (0, _react.useState)({}),
|
|
39
57
|
headerActions = _useState2[0],
|
|
40
58
|
setHeaderActions = _useState2[1];
|
|
41
|
-
var _useState3 = (0, _react.useState)(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
setShowMessage = _useState5[1];
|
|
49
|
-
var _useState6 = (0, _react.useState)({
|
|
59
|
+
var _useState3 = (0, _react.useState)(props.expanded),
|
|
60
|
+
expanded = _useState3[0],
|
|
61
|
+
setExpanded = _useState3[1];
|
|
62
|
+
var _useState4 = (0, _react.useState)(false),
|
|
63
|
+
showmessage = _useState4[0],
|
|
64
|
+
setShowMessage = _useState4[1];
|
|
65
|
+
var _useState5 = (0, _react.useState)({
|
|
50
66
|
caption: "",
|
|
51
67
|
type: ""
|
|
52
68
|
}),
|
|
53
|
-
statusMessage =
|
|
54
|
-
setStatusMessage =
|
|
69
|
+
statusMessage = _useState5[0],
|
|
70
|
+
setStatusMessage = _useState5[1];
|
|
71
|
+
var parentFormData = parentForm ? (_props$listener = props.listener) === null || _props$listener === void 0 || (_props$listener = _props$listener.Widgets) === null || _props$listener === void 0 || (_props$listener = _props$listener[parentForm]) === null || _props$listener === void 0 ? void 0 : _props$listener.formdata : undefined;
|
|
72
|
+
var _useState6 = (0, _react.useState)(),
|
|
73
|
+
childFormData = _useState6[0],
|
|
74
|
+
setChildFormData = _useState6[1];
|
|
55
75
|
var messageRef = (0, _react.useRef)(null);
|
|
56
76
|
var _useState7 = (0, _react.useState)(false),
|
|
57
77
|
showViewMode = _useState7[0],
|
|
58
78
|
setShowViewMode = _useState7[1];
|
|
79
|
+
var lastResetFormDataRef = (0, _react.useRef)(null);
|
|
80
|
+
var childFormUnsubscribeRef = (0, _react.useRef)(null);
|
|
81
|
+
var parentFormUnsubscribeRef = (0, _react.useRef)(null);
|
|
82
|
+
var validationMessagesRef = (0, _react.useRef)([]);
|
|
83
|
+
var widgetFormData = props.name && (_props$listener2 = props.listener) !== null && _props$listener2 !== void 0 && (_props$listener2 = _props$listener2.Widgets) !== null && _props$listener2 !== void 0 && (_props$listener2 = _props$listener2[props.name]) !== null && _props$listener2 !== void 0 && _props$listener2.formdata && Object.keys(props.listener.Widgets[props.name].formdata).length > 0 ? props.listener.Widgets[props.name].formdata : props.formdata;
|
|
84
|
+
var formDataref = (0, _react.useRef)(null);
|
|
85
|
+
var updateFormData = function updateFormData(data) {
|
|
86
|
+
if (typeof data === "function") {
|
|
87
|
+
// If data is a function, call it with current form data
|
|
88
|
+
formDataref.current = data(formDataref.current || {});
|
|
89
|
+
} else {
|
|
90
|
+
// Otherwise, merge as before
|
|
91
|
+
formDataref.current = (0, _merge["default"])({}, formDataref.current, data);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
59
94
|
var _useForm = (0, _reactHookForm.useForm)({
|
|
60
|
-
defaultValues: props.
|
|
95
|
+
defaultValues: props.formdata,
|
|
61
96
|
mode: "onTouched",
|
|
62
97
|
reValidateMode: "onBlur"
|
|
63
98
|
}),
|
|
@@ -66,41 +101,386 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
66
101
|
_useForm$formState = _useForm.formState,
|
|
67
102
|
errors = _useForm$formState.errors,
|
|
68
103
|
isValid = _useForm$formState.isValid,
|
|
104
|
+
submitCount = _useForm$formState.submitCount,
|
|
69
105
|
reset = _useForm.reset,
|
|
70
106
|
watch = _useForm.watch,
|
|
71
107
|
trigger = _useForm.trigger,
|
|
72
108
|
getValues = _useForm.getValues,
|
|
73
|
-
clearErrors = _useForm.clearErrors
|
|
109
|
+
clearErrors = _useForm.clearErrors,
|
|
110
|
+
setValue = _useForm.setValue,
|
|
111
|
+
resetField = _useForm.resetField;
|
|
112
|
+
|
|
113
|
+
// update valid state
|
|
114
|
+
(0, _react.useEffect)(function () {
|
|
115
|
+
var _props$listener3;
|
|
116
|
+
if ((_props$listener3 = props.listener) !== null && _props$listener3 !== void 0 && _props$listener3.onChange && props.name) {
|
|
117
|
+
props.listener.onChange(props.name, {
|
|
118
|
+
valid: isValid
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}, [isValid]);
|
|
122
|
+
var childFormEventListeners = function childFormEventListeners() {
|
|
123
|
+
if (parentForm && props.name) {
|
|
124
|
+
// Listen for parent relationship events (context, acknowledgments, etc.)
|
|
125
|
+
var parentContextUnsubscribe = _events.EVENTEMITTER_METHODS.CHILD_FORM_RELATIONSHIP_ON(props.name, function (parentContext) {
|
|
126
|
+
// Only process context updates (not registration events)
|
|
127
|
+
if (parentContext && parentContext.action === "context" && parentContext.formData !== undefined) {
|
|
128
|
+
var childData = parentContext.formData;
|
|
129
|
+
|
|
130
|
+
// For list forms, the formData is already the specific array item, use it directly
|
|
131
|
+
if (effectiveChildDatasetNode && (0, _typeof2["default"])(parentContext.formData) === "object" && !Array.isArray(parentContext.formData)) {
|
|
132
|
+
// For regular child forms, check if the data is already the child data or if we need to extract it
|
|
133
|
+
// If the parent form data has the childdatasetnode as a key, extract it
|
|
134
|
+
// Otherwise, assume the formData is already the child data
|
|
135
|
+
if (parentContext.formData.hasOwnProperty(effectiveChildDatasetNode)) {
|
|
136
|
+
childData = (0, _get["default"])(parentContext.formData, effectiveChildDatasetNode);
|
|
137
|
+
}
|
|
138
|
+
// The formData is already the child data, use it directly
|
|
139
|
+
}
|
|
140
|
+
if (childData && (0, _typeof2["default"])(childData) === "object" && !Array.isArray(childData)) {
|
|
141
|
+
// Update child form with data from parent context
|
|
142
|
+
var currentValues = getValues();
|
|
143
|
+
if (!(0, _isEqual["default"])(childData, currentValues) && !(0, _isEqual["default"])(childData, lastResetFormDataRef.current)) {
|
|
144
|
+
reset(childData);
|
|
145
|
+
lastResetFormDataRef.current = childData;
|
|
146
|
+
}
|
|
147
|
+
} else if (childData === null || childData === undefined || Array.isArray(childData) && childData.length === 0) {
|
|
148
|
+
// Handle empty data case
|
|
149
|
+
var emptyData = {};
|
|
150
|
+
if (!(0, _isEqual["default"])(emptyData, getValues())) {
|
|
151
|
+
reset(emptyData);
|
|
152
|
+
lastResetFormDataRef.current = emptyData;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, false, props["data-widget-id"], false // isRegistration = false for context updates
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// Register child form with parent
|
|
160
|
+
_events.EVENTEMITTER_METHODS.CHILD_FORM_RELATIONSHIP_EMIT(parentForm, {
|
|
161
|
+
childFormName: props.name,
|
|
162
|
+
childdatasetnode: effectiveChildDatasetNode,
|
|
163
|
+
childWidgetId: props["data-widget-id"],
|
|
164
|
+
isListForm: isParentList,
|
|
165
|
+
formArrayIndex: isParentList ? formArrayIndex : undefined,
|
|
166
|
+
formInstance: {
|
|
167
|
+
getValues: getValues,
|
|
168
|
+
reset: reset,
|
|
169
|
+
setFormData: setFormData
|
|
170
|
+
},
|
|
171
|
+
action: "register"
|
|
172
|
+
}, true, undefined,
|
|
173
|
+
// No widget ID for registration event names
|
|
174
|
+
true // isRegistration = true
|
|
175
|
+
); // isParent = true to emit to parent's listening channel
|
|
176
|
+
|
|
177
|
+
return function () {
|
|
178
|
+
parentContextUnsubscribe();
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var parentFormEventListeners = function parentFormEventListeners() {
|
|
183
|
+
if (props.name) {
|
|
184
|
+
var unsubscribe = _events.EVENTEMITTER_METHODS.CHILD_FORM_RELATIONSHIP_ON(props.name, function (data) {
|
|
185
|
+
var childFormName = data.childFormName,
|
|
186
|
+
childdatasetnode = data.childdatasetnode,
|
|
187
|
+
action = data.action,
|
|
188
|
+
childWidgetId = data.childWidgetId;
|
|
189
|
+
if (action === "register" && childFormName && childdatasetnode) {
|
|
190
|
+
// Send current parent context to the newly registered child
|
|
191
|
+
var currentParentData = getValues();
|
|
192
|
+
|
|
193
|
+
// For list forms, extract the specific array item based on formArrayIndex
|
|
194
|
+
var _childFormData = currentParentData;
|
|
195
|
+
if (data.isListForm && typeof data.formArrayIndex === "number" && data.formArrayIndex >= 0) {
|
|
196
|
+
var listData = (0, _get["default"])(currentParentData, childdatasetnode);
|
|
197
|
+
if (Array.isArray(listData) && data.formArrayIndex < listData.length) {
|
|
198
|
+
_childFormData = listData[data.formArrayIndex];
|
|
199
|
+
} else {
|
|
200
|
+
_childFormData = {};
|
|
201
|
+
}
|
|
202
|
+
} else if (!data.isListForm && childdatasetnode) {
|
|
203
|
+
// For regular child forms, get the object property
|
|
204
|
+
_childFormData = (0, _get["default"])(currentParentData, childdatasetnode);
|
|
205
|
+
}
|
|
206
|
+
_events.EVENTEMITTER_METHODS.CHILD_FORM_RELATIONSHIP_EMIT(childFormName, {
|
|
207
|
+
parentFormName: props.name,
|
|
208
|
+
childFormName: childFormName,
|
|
209
|
+
childdatasetnode: childdatasetnode,
|
|
210
|
+
formData: _childFormData,
|
|
211
|
+
timestamp: Date.now(),
|
|
212
|
+
action: "context"
|
|
213
|
+
}, false, childWidgetId, false // isRegistration = false for context updates
|
|
214
|
+
); // isParent = false to emit to child's listening channel
|
|
215
|
+
}
|
|
216
|
+
}, true,
|
|
217
|
+
// isParent = true
|
|
218
|
+
undefined,
|
|
219
|
+
// No widget ID for registration listening
|
|
220
|
+
true // isRegistration = true
|
|
221
|
+
);
|
|
222
|
+
return function () {
|
|
223
|
+
unsubscribe();
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
var parentFormDataUpdateListeners = function parentFormDataUpdateListeners() {
|
|
228
|
+
// Only set up listeners for parent forms (forms that have child forms), not for child forms themselves
|
|
229
|
+
if (!parentForm && props.name) {
|
|
230
|
+
var unsubscribe = _events.EVENTEMITTER_METHODS.CHILD_FORM_DATA_UPDATE_ON(props.name, function (data) {
|
|
231
|
+
var childdatasetnode = data.childdatasetnode,
|
|
232
|
+
formData = data.formData,
|
|
233
|
+
isListForm = data.isListForm,
|
|
234
|
+
formArrayIndex = data.formArrayIndex;
|
|
235
|
+
if (childdatasetnode && formData) {
|
|
236
|
+
var _props$listener4, _props$listener5, _props$listener5$onCh;
|
|
237
|
+
// Get current parent form values
|
|
238
|
+
var currentParentData = getValues();
|
|
239
|
+
|
|
240
|
+
// Update the parent form's data
|
|
241
|
+
var updatedParentData = _objectSpread({}, currentParentData);
|
|
242
|
+
if (isListForm && typeof formArrayIndex === "number" && formArrayIndex >= 0) {
|
|
243
|
+
// Handle array updates for forms inside lists
|
|
244
|
+
var listData = (0, _get["default"])(updatedParentData, childdatasetnode);
|
|
245
|
+
if (Array.isArray(listData)) {
|
|
246
|
+
// Update the specific array index
|
|
247
|
+
listData[formArrayIndex] = _objectSpread(_objectSpread({}, listData[formArrayIndex]), formData);
|
|
248
|
+
(0, _set["default"])(updatedParentData, childdatasetnode, listData);
|
|
249
|
+
} else {
|
|
250
|
+
// Initialize array if it doesn't exist
|
|
251
|
+
var newArray = [];
|
|
252
|
+
newArray[formArrayIndex] = formData;
|
|
253
|
+
(0, _set["default"])(updatedParentData, childdatasetnode, newArray);
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
// Handle object property updates for regular child forms
|
|
257
|
+
(0, _set["default"])(updatedParentData, childdatasetnode, formData);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// First update the widget formdata to ensure consistency
|
|
261
|
+
if ((_props$listener4 = props.listener) !== null && _props$listener4 !== void 0 && (_props$listener4 = _props$listener4.Widgets) !== null && _props$listener4 !== void 0 && _props$listener4[props.name]) {
|
|
262
|
+
props.listener.Widgets[props.name].formdata = updatedParentData;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Update the parent form's React Hook Form state
|
|
266
|
+
reset(updatedParentData);
|
|
267
|
+
|
|
268
|
+
// Additionally, ensure the nested data is properly set using setValue
|
|
269
|
+
setTimeout(function () {
|
|
270
|
+
try {
|
|
271
|
+
if (isListForm && typeof formArrayIndex === "number" && formArrayIndex >= 0) {
|
|
272
|
+
// For list forms, update the specific array index
|
|
273
|
+
var arrayPath = "".concat(childdatasetnode, "[").concat(formArrayIndex, "]");
|
|
274
|
+
setValue(arrayPath, formData, {
|
|
275
|
+
shouldValidate: false,
|
|
276
|
+
shouldDirty: true
|
|
277
|
+
});
|
|
278
|
+
} else {
|
|
279
|
+
// For regular child forms, update the object property
|
|
280
|
+
setValue(childdatasetnode, formData, {
|
|
281
|
+
shouldValidate: false,
|
|
282
|
+
shouldDirty: true
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
} catch (error) {
|
|
286
|
+
// Fallback: try to set individual fields within the nested object/array
|
|
287
|
+
if ((0, _typeof2["default"])(formData) === "object" && formData !== null) {
|
|
288
|
+
Object.keys(formData).forEach(function (subField) {
|
|
289
|
+
var fullPath = isListForm && typeof formArrayIndex === "number" ? "".concat(childdatasetnode, "[").concat(formArrayIndex, "].").concat(subField) : "".concat(childdatasetnode, ".").concat(subField);
|
|
290
|
+
setValue(fullPath, formData[subField], {
|
|
291
|
+
shouldValidate: false,
|
|
292
|
+
shouldDirty: true
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}, 0);
|
|
298
|
+
|
|
299
|
+
// Emit the updated parent form data
|
|
300
|
+
(_props$listener5 = props.listener) === null || _props$listener5 === void 0 || (_props$listener5$onCh = _props$listener5.onChange) === null || _props$listener5$onCh === void 0 || _props$listener5$onCh.call(_props$listener5, props.name, {
|
|
301
|
+
dataoutput: updatedParentData
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
return function () {
|
|
306
|
+
unsubscribe();
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
var parentFormFieldRegisterListeners = function parentFormFieldRegisterListeners() {
|
|
311
|
+
var _props$listener6;
|
|
312
|
+
// Only set up listeners for parent forms (forms that have child forms), not for child forms themselves
|
|
313
|
+
if (!parentForm && props.name && (_props$listener6 = props.listener) !== null && _props$listener6 !== void 0 && _props$listener6.Widgets) {
|
|
314
|
+
var unsubscribe = _events.EVENTEMITTER_METHODS.CHILD_FORM_FIELD_REGISTER_ON(props.name, function (data) {
|
|
315
|
+
var _props$listener7;
|
|
316
|
+
var childFormName = data.childFormName,
|
|
317
|
+
widget = data.widget,
|
|
318
|
+
widgetProps = data.widgetProps,
|
|
319
|
+
formKey = data.formKey,
|
|
320
|
+
fieldName = data.fieldName;
|
|
321
|
+
if (childFormName && widget && formKey && fieldName && (_props$listener7 = props.listener) !== null && _props$listener7 !== void 0 && (_props$listener7 = _props$listener7.Widgets) !== null && _props$listener7 !== void 0 && _props$listener7[props.name]) {
|
|
322
|
+
// Ensure the form structure exists in the parent form's widgetsContext
|
|
323
|
+
var parentFormContext = props.listener.Widgets[props.name];
|
|
324
|
+
parentFormContext.formfields = parentFormContext.formfields || {};
|
|
325
|
+
parentFormContext.formWidgets = parentFormContext.formWidgets || {};
|
|
326
|
+
|
|
327
|
+
// Register the field using the formKey (primary key)
|
|
328
|
+
parentFormContext.formfields[formKey] = widget;
|
|
329
|
+
|
|
330
|
+
// Register using fieldName for direct access
|
|
331
|
+
parentFormContext.formWidgets[fieldName] = widget;
|
|
332
|
+
|
|
333
|
+
// Register formWidget variants (for form field wrapper components)
|
|
334
|
+
parentFormContext.formfields["".concat(fieldName, "_formWidget")] = widget;
|
|
335
|
+
parentFormContext.formWidgets["".concat(fieldName, "_formWidget")] = widget;
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
return function () {
|
|
339
|
+
unsubscribe();
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// Track the last formdata that was used to reset the form
|
|
346
|
+
// This prevents unnecessary resets when formdata prop reference changes but values are the same
|
|
347
|
+
|
|
348
|
+
(0, _react.useEffect)(function () {
|
|
349
|
+
if (parentFormData) {
|
|
350
|
+
var childData;
|
|
351
|
+
if (isParentList && formArrayIndex >= 0 && effectiveChildDatasetNode) {
|
|
352
|
+
// Forms inside lists read from array indices: parentForm.formdata[listName][formArrayIndex]
|
|
353
|
+
var listData = (0, _get["default"])(parentFormData, effectiveChildDatasetNode);
|
|
354
|
+
if (listData && Array.isArray(listData) && formArrayIndex < listData.length) {
|
|
355
|
+
childData = listData[formArrayIndex];
|
|
356
|
+
} else {
|
|
357
|
+
childData = null;
|
|
358
|
+
}
|
|
359
|
+
} else if (effectiveChildDatasetNode) {
|
|
360
|
+
// Regular child forms use object properties: parentForm.formdata[childDatasetNode]
|
|
361
|
+
childData = (0, _get["default"])(parentFormData, effectiveChildDatasetNode);
|
|
362
|
+
} else {
|
|
363
|
+
childData = null;
|
|
364
|
+
}
|
|
365
|
+
setChildFormData(childData);
|
|
366
|
+
}
|
|
367
|
+
}, [parentFormData, props === null || props === void 0 ? void 0 : props.dataKey, effectiveChildDatasetNode, props === null || props === void 0 ? void 0 : props.name, isParentList, formArrayIndex]);
|
|
368
|
+
|
|
369
|
+
// Register child form with parent form if parentForm exists
|
|
370
|
+
(0, _react.useEffect)(function () {
|
|
371
|
+
if (prefabContext !== null && prefabContext !== void 0 && prefabContext.parentForm && props.name) {
|
|
372
|
+
childFormEventListeners();
|
|
373
|
+
}
|
|
374
|
+
}, [parentForm, props.name, effectiveChildDatasetNode, getValues, reset]);
|
|
375
|
+
|
|
376
|
+
// Listen for child form relationship events (for parent forms)
|
|
377
|
+
(0, _react.useEffect)(function () {
|
|
378
|
+
parentFormEventListeners();
|
|
379
|
+
parentFormDataUpdateListeners();
|
|
380
|
+
parentFormFieldRegisterListeners();
|
|
381
|
+
}, [props.name, getValues, reset]);
|
|
382
|
+
|
|
383
|
+
// Listen for external parent formdata changes (for child forms)
|
|
384
|
+
(0, _react.useEffect)(function () {
|
|
385
|
+
if (!parentForm || !effectiveChildDatasetNode) return;
|
|
386
|
+
var handleParentFormDataChange = function handleParentFormDataChange(data) {
|
|
387
|
+
var parentFormName = data.parentFormName,
|
|
388
|
+
formData = data.formData;
|
|
389
|
+
if (parentFormName === parentForm && formData) {
|
|
390
|
+
// Extract child data from the updated parent form data
|
|
391
|
+
var childData = (0, _get["default"])(formData, effectiveChildDatasetNode);
|
|
392
|
+
var finalChildData = childData;
|
|
393
|
+
if (isParentList && formArrayIndex >= 0 && Array.isArray(childData)) {
|
|
394
|
+
finalChildData = childData[formArrayIndex];
|
|
395
|
+
}
|
|
396
|
+
if (finalChildData && (0, _typeof2["default"])(finalChildData) === "object") {
|
|
397
|
+
resetFormWithData(finalChildData);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var unsubscribe = _events.EVENTEMITTER_METHODS.PARENT_FORM_EXTERNAL_DATA_CHANGE_ON(handleParentFormDataChange);
|
|
402
|
+
return unsubscribe;
|
|
403
|
+
}, [parentForm, effectiveChildDatasetNode, props.name, getValues, reset]);
|
|
74
404
|
|
|
75
405
|
// update the form data when the formdata prop changes
|
|
76
406
|
(0, _react.useEffect)(function () {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
407
|
+
// For child forms, prioritize childFormData over widgetFormData
|
|
408
|
+
var formDataToUse = props.parentForm ? childFormData || widgetFormData || props.formdata : widgetFormData || childFormData || props.formdata;
|
|
409
|
+
if (formDataToUse && (0, _typeof2["default"])(formDataToUse) === "object" && !Array.isArray(formDataToUse)) {
|
|
410
|
+
// Get current form values to compare
|
|
411
|
+
var currentFormValues = getValues();
|
|
412
|
+
|
|
413
|
+
// Deep compare with the last formdata that was used to reset
|
|
414
|
+
// Only reset if formdata has actually changed (not just reference change)
|
|
415
|
+
var hasFormDataChanged = !(0, _isEqual["default"])(formDataToUse, lastResetFormDataRef.current);
|
|
416
|
+
|
|
417
|
+
// Also check if formDataToUse differs from current form values
|
|
418
|
+
// This prevents resetting when form is already in the correct state
|
|
419
|
+
var differsFromCurrentValues = !(0, _isEqual["default"])(formDataToUse, currentFormValues);
|
|
420
|
+
if (hasFormDataChanged && differsFromCurrentValues) {
|
|
421
|
+
// when adding new row if the formdata is empty it should be reset here this code is added to not avoid the empty formdata case
|
|
422
|
+
// Reset to empty if formdata is empty object (for new records)
|
|
423
|
+
if (Object.keys(formDataToUse).length === 0) {
|
|
424
|
+
// Get all currently registered field names and create explicit empty values
|
|
425
|
+
var currentValues = getValues();
|
|
426
|
+
var emptyValues = {};
|
|
427
|
+
Object.keys(currentValues).forEach(function (key) {
|
|
428
|
+
emptyValues[key] = currentValues[key]; // Explicitly set each field to empty string
|
|
429
|
+
});
|
|
430
|
+
resetFormWithData(emptyValues);
|
|
431
|
+
} else {
|
|
432
|
+
// Reset with actual data (for editing)
|
|
433
|
+
resetFormWithData(formDataToUse);
|
|
434
|
+
if (props["form-type"] === "live-filter") {
|
|
435
|
+
debouncedFilter();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
81
438
|
}
|
|
82
439
|
}
|
|
83
|
-
}, [props.formdata, reset]);
|
|
440
|
+
}, [props.formdata, widgetFormData, childFormData, reset, getValues, props.parentForm]);
|
|
84
441
|
function debouncedFilter() {
|
|
85
442
|
var debouncedFilter = (0, _lodashEs.debounce)(filter, 250);
|
|
86
443
|
debouncedFilter();
|
|
87
444
|
}
|
|
88
|
-
var formreset = function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
445
|
+
var formreset = /*#__PURE__*/function () {
|
|
446
|
+
var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
447
|
+
var _formReff$current;
|
|
448
|
+
var cleanedData, el;
|
|
449
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
450
|
+
while (1) switch (_context.prev = _context.next) {
|
|
451
|
+
case 0:
|
|
452
|
+
cleanedData = {};
|
|
453
|
+
Object.keys(formfields).forEach(function (key) {
|
|
454
|
+
if (formfields[key].formName !== props.name) return;
|
|
455
|
+
// do not reset for readonly and disabled fields
|
|
456
|
+
if (formfields[key].readonly || formfields[key].readOnly || formfields[key].disabled) {
|
|
457
|
+
cleanedData[key] = formfields[key].defaultvalue || formfields[key].value;
|
|
458
|
+
} else {
|
|
459
|
+
cleanedData[key] = "";
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
_context.next = 4;
|
|
463
|
+
return reset(cleanedData);
|
|
464
|
+
case 4:
|
|
465
|
+
trigger();
|
|
466
|
+
// dispatching an event for uncontrolled widget like seach widget clear inside the chips widget.
|
|
467
|
+
el = formRef.current;
|
|
468
|
+
if (el) {
|
|
469
|
+
el.dispatchEvent(new CustomEvent("wmformreset", {
|
|
470
|
+
bubbles: true
|
|
471
|
+
}));
|
|
472
|
+
}
|
|
473
|
+
(formReff === null || formReff === void 0 ? void 0 : formReff.current) && (formReff === null || formReff === void 0 || (_formReff$current = formReff.current) === null || _formReff$current === void 0 ? void 0 : _formReff$current.formreset());
|
|
474
|
+
case 8:
|
|
475
|
+
case "end":
|
|
476
|
+
return _context.stop();
|
|
477
|
+
}
|
|
478
|
+
}, _callee);
|
|
479
|
+
}));
|
|
480
|
+
return function formreset() {
|
|
481
|
+
return _ref.apply(this, arguments);
|
|
482
|
+
};
|
|
483
|
+
}();
|
|
104
484
|
var isElementInViewport = function isElementInViewport(el) {
|
|
105
485
|
if (!el) return false;
|
|
106
486
|
var rect = el.getBoundingClientRect();
|
|
@@ -147,8 +527,8 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
147
527
|
scrollToElement(formEl);
|
|
148
528
|
}
|
|
149
529
|
} else {
|
|
150
|
-
var _props$
|
|
151
|
-
props === null || props === void 0 || (_props$
|
|
530
|
+
var _props$listener8;
|
|
531
|
+
props === null || props === void 0 || (_props$listener8 = props.listener) === null || _props$listener8 === void 0 || (_props$listener8 = _props$listener8.App) === null || _props$listener8 === void 0 || _props$listener8.notifyApp(template, type, true);
|
|
152
532
|
}
|
|
153
533
|
} else {
|
|
154
534
|
setStatusMessage({
|
|
@@ -160,111 +540,422 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
160
540
|
scrollToElement(formRef.current);
|
|
161
541
|
}
|
|
162
542
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Creates a validation message object for a field with errors.
|
|
546
|
+
* Simplified - only adds entries (array is cleared before each build).
|
|
547
|
+
*/
|
|
548
|
+
var addValidationMessage = (0, _react.useCallback)(function (fieldErrors, fieldKey, field, prefix) {
|
|
549
|
+
var _field$value;
|
|
550
|
+
var errorTypes = (0, _formUtils.getErrorTypes)(fieldErrors);
|
|
551
|
+
validationMessagesRef.current.push({
|
|
552
|
+
field: fieldKey,
|
|
553
|
+
value: (_field$value = field === null || field === void 0 ? void 0 : field.value) !== null && _field$value !== void 0 ? _field$value : field === null || field === void 0 ? void 0 : field.datavalue,
|
|
554
|
+
errorType: errorTypes,
|
|
555
|
+
message: (field === null || field === void 0 ? void 0 : field.validationmessage) || (fieldErrors === null || fieldErrors === void 0 ? void 0 : fieldErrors.message) || "",
|
|
556
|
+
getElement: function getElement() {
|
|
557
|
+
var formEl = formRef.current;
|
|
558
|
+
if (formEl) {
|
|
559
|
+
var fieldEl = formEl.querySelector("[name=\"".concat(fieldKey, "\"]"));
|
|
560
|
+
if (fieldEl) {
|
|
561
|
+
return fieldEl.closest("[focus-target]") || fieldEl.querySelector("[focus-target]") || fieldEl;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return null;
|
|
565
|
+
},
|
|
566
|
+
formName: (0, _lodashEs.last)(prefix.split(".")) || props.name || "",
|
|
567
|
+
fullyQualifiedFormName: prefix
|
|
568
|
+
});
|
|
569
|
+
}, [props.name]);
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Exposes validationMessages on widget object and formRef for external access.
|
|
573
|
+
* DRY helper to avoid repeating this pattern.
|
|
574
|
+
*/
|
|
575
|
+
var exposeValidationMessages = (0, _react.useCallback)(function (validationMessages) {
|
|
576
|
+
var _props$listener9;
|
|
577
|
+
if ((_props$listener9 = props.listener) !== null && _props$listener9 !== void 0 && (_props$listener9 = _props$listener9.Widgets) !== null && _props$listener9 !== void 0 && _props$listener9[props.name]) {
|
|
578
|
+
props.listener.Widgets[props.name].validationMessages = validationMessages;
|
|
579
|
+
}
|
|
580
|
+
if (formRef.current) {
|
|
581
|
+
formRef.current.validationMessages = validationMessages;
|
|
582
|
+
}
|
|
583
|
+
}, [props.name]);
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Gets the form fields to validate and their keys.
|
|
587
|
+
* DRY helper for shared iteration setup.
|
|
588
|
+
*/
|
|
589
|
+
var getFormFieldsForValidation = (0, _react.useCallback)(function () {
|
|
590
|
+
var _props$listener0;
|
|
591
|
+
var formFieldsToValidate = ((_props$listener0 = props.listener) === null || _props$listener0 === void 0 || (_props$listener0 = _props$listener0.Widgets) === null || _props$listener0 === void 0 || (_props$listener0 = _props$listener0[props.name]) === null || _props$listener0 === void 0 ? void 0 : _props$listener0.formfields) || formfields;
|
|
592
|
+
var allFieldKeys = Object.keys(formFieldsToValidate);
|
|
593
|
+
var prefix = props.name || "";
|
|
594
|
+
return {
|
|
595
|
+
formFieldsToValidate: formFieldsToValidate,
|
|
596
|
+
allFieldKeys: allFieldKeys,
|
|
597
|
+
prefix: prefix
|
|
598
|
+
};
|
|
599
|
+
}, [props.name, formfields]);
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Core validation messages builder that accepts a getFieldError function.
|
|
603
|
+
* This allows both sync and async validation to share the same iteration logic.
|
|
604
|
+
*/
|
|
605
|
+
var buildValidationMessagesCore = (0, _react.useCallback)(function (getFieldError) {
|
|
606
|
+
validationMessagesRef.current = [];
|
|
607
|
+
var _getFormFieldsForVali = getFormFieldsForValidation(),
|
|
608
|
+
formFieldsToValidate = _getFormFieldsForVali.formFieldsToValidate,
|
|
609
|
+
allFieldKeys = _getFormFieldsForVali.allFieldKeys,
|
|
610
|
+
prefix = _getFormFieldsForVali.prefix;
|
|
611
|
+
allFieldKeys.forEach(function (fieldKey) {
|
|
612
|
+
if ((0, _formUtils.shouldSkipFieldKey)(fieldKey, allFieldKeys)) return;
|
|
613
|
+
var field = formFieldsToValidate[fieldKey];
|
|
614
|
+
var fieldErrors = getFieldError(fieldKey, field);
|
|
615
|
+
if (fieldErrors) {
|
|
616
|
+
addValidationMessage(fieldErrors, fieldKey, field, prefix);
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
return validationMessagesRef.current;
|
|
620
|
+
}, [getFormFieldsForValidation, addValidationMessage]);
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Builds validation messages using react-hook-form's state.
|
|
624
|
+
* Uses control.getFieldState() to get error state.
|
|
625
|
+
* Call trigger() before this to ensure validation has run.
|
|
626
|
+
*/
|
|
627
|
+
var buildValidationMessages = (0, _react.useCallback)(function () {
|
|
628
|
+
return buildValidationMessagesCore(function (fieldKey) {
|
|
629
|
+
var fieldState = control.getFieldState(fieldKey);
|
|
630
|
+
return fieldState === null || fieldState === void 0 ? void 0 : fieldState.error;
|
|
631
|
+
});
|
|
632
|
+
}, [buildValidationMessagesCore, control]);
|
|
633
|
+
var validateFieldsOnSubmit = (0, _react.useCallback)(/*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
634
|
+
var isValid, currentFormValidState, _props$listener1;
|
|
635
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
636
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
637
|
+
case 0:
|
|
638
|
+
if (!formReff.current) {
|
|
639
|
+
_context2.next = 6;
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
_context2.next = 3;
|
|
643
|
+
return formReff.current.validateFieldsOnSubmit();
|
|
644
|
+
case 3:
|
|
645
|
+
_context2.t0 = _context2.sent;
|
|
646
|
+
_context2.next = 7;
|
|
647
|
+
break;
|
|
648
|
+
case 6:
|
|
649
|
+
_context2.t0 = true;
|
|
650
|
+
case 7:
|
|
651
|
+
isValid = _context2.t0;
|
|
652
|
+
_context2.next = 10;
|
|
653
|
+
return trigger();
|
|
654
|
+
case 10:
|
|
655
|
+
currentFormValidState = _context2.sent;
|
|
656
|
+
if (!(!isValid || !currentFormValidState)) {
|
|
657
|
+
_context2.next = 14;
|
|
658
|
+
break;
|
|
659
|
+
}
|
|
660
|
+
if (!currentFormValidState) {
|
|
661
|
+
props === null || props === void 0 || (_props$listener1 = props.listener) === null || _props$listener1 === void 0 || _props$listener1.onChange(props.name, {
|
|
185
662
|
valid: false,
|
|
186
663
|
errors: errors
|
|
187
664
|
});
|
|
188
|
-
|
|
189
|
-
|
|
665
|
+
}
|
|
666
|
+
return _context2.abrupt("return", false);
|
|
667
|
+
case 14:
|
|
668
|
+
return _context2.abrupt("return", true);
|
|
669
|
+
case 15:
|
|
670
|
+
case "end":
|
|
671
|
+
return _context2.stop();
|
|
672
|
+
}
|
|
673
|
+
}, _callee2);
|
|
674
|
+
})), [formReff, trigger, buildValidationMessages, exposeValidationMessages, errors, props.name]);
|
|
675
|
+
var updateFormDataOutput = function updateFormDataOutput(data, formWidgets) {
|
|
676
|
+
// Set the values of the widgets inside the live form (other than form fields) in form data
|
|
677
|
+
Object.keys(formWidgets).forEach(function (key) {
|
|
678
|
+
if (!(0, _lodashEs.find)(data, {
|
|
679
|
+
key: key
|
|
680
|
+
})) {
|
|
681
|
+
data[key] = formWidgets[key];
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
return data;
|
|
685
|
+
};
|
|
686
|
+
var handleFormSubmit = /*#__PURE__*/function () {
|
|
687
|
+
var _ref3 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(data, e, operationType) {
|
|
688
|
+
var _props$listener10, _props$onSubmit;
|
|
689
|
+
var formWidgets, filteredData, mergedData, result, formData;
|
|
690
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
691
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
692
|
+
case 0:
|
|
693
|
+
e = e || new Event("submit");
|
|
694
|
+
formWidgets = (_props$listener10 = props.listener) === null || _props$listener10 === void 0 || (_props$listener10 = _props$listener10.Widgets) === null || _props$listener10 === void 0 || (_props$listener10 = _props$listener10[props.name]) === null || _props$listener10 === void 0 ? void 0 : _props$listener10.dataoutput;
|
|
695
|
+
if (formWidgets && Object.keys(formWidgets).length > 0) {
|
|
696
|
+
data = updateFormDataOutput(data, formWidgets);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// Filter and merge data
|
|
700
|
+
filteredData = filterTableColumns(data);
|
|
701
|
+
mergedData = mergeWithFormDataRef(filteredData); // Execute onBeforeSubmit hook
|
|
190
702
|
if (!props.onBeforeSubmit) {
|
|
191
|
-
|
|
703
|
+
_context3.next = 11;
|
|
192
704
|
break;
|
|
193
705
|
}
|
|
194
|
-
|
|
195
|
-
return props.onBeforeSubmit(e, props,
|
|
196
|
-
case
|
|
197
|
-
result =
|
|
706
|
+
_context3.next = 8;
|
|
707
|
+
return props.onBeforeSubmit(e, props, mergedData);
|
|
708
|
+
case 8:
|
|
709
|
+
result = _context3.sent;
|
|
198
710
|
if (!(result === false)) {
|
|
199
|
-
|
|
711
|
+
_context3.next = 11;
|
|
200
712
|
break;
|
|
201
713
|
}
|
|
202
|
-
return
|
|
203
|
-
case
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
714
|
+
return _context3.abrupt("return");
|
|
715
|
+
case 11:
|
|
716
|
+
// Transform flat data to nested structure
|
|
717
|
+
formData = transformToNestedObject(mergedData); // Handle form submission
|
|
718
|
+
notifyDataOutput(mergedData);
|
|
719
|
+
_context3.next = 15;
|
|
720
|
+
return executeFormSubmit(formData, operationType);
|
|
721
|
+
case 15:
|
|
722
|
+
// Execute onSubmit hook
|
|
723
|
+
props === null || props === void 0 || (_props$onSubmit = props.onSubmit) === null || _props$onSubmit === void 0 || _props$onSubmit.call(props, e, props, formData);
|
|
724
|
+
case 16:
|
|
725
|
+
case "end":
|
|
726
|
+
return _context3.stop();
|
|
727
|
+
}
|
|
728
|
+
}, _callee3);
|
|
729
|
+
}));
|
|
730
|
+
return function handleFormSubmit(_x, _x2, _x3) {
|
|
731
|
+
return _ref3.apply(this, arguments);
|
|
732
|
+
};
|
|
733
|
+
}();
|
|
216
734
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
735
|
+
// Helper functions
|
|
736
|
+
var filterTableColumns = function filterTableColumns(data) {
|
|
737
|
+
return Object.keys(data).reduce(function (acc, key) {
|
|
738
|
+
if (!key.startsWith("wm_table_column_")) {
|
|
739
|
+
acc[key] = data[key];
|
|
740
|
+
}
|
|
741
|
+
return acc;
|
|
742
|
+
}, {});
|
|
743
|
+
};
|
|
744
|
+
var mergeWithFormDataRef = function mergeWithFormDataRef(data) {
|
|
745
|
+
if (!formDataref.current) return data;
|
|
746
|
+
var merged = _objectSpread({}, data);
|
|
747
|
+
Object.keys(formDataref.current).forEach(function (key) {
|
|
748
|
+
if (formDataref.current.hasOwnProperty(key)) {
|
|
749
|
+
merged[key] = formDataref.current[key] || [];
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
return merged;
|
|
753
|
+
};
|
|
754
|
+
var transformToNestedObject = function transformToNestedObject(data) {
|
|
755
|
+
var result = {};
|
|
756
|
+
Object.keys(data).forEach(function (key) {
|
|
757
|
+
(0, _set["default"])(result, key, data[key]);
|
|
758
|
+
});
|
|
759
|
+
return result;
|
|
760
|
+
};
|
|
761
|
+
var notifyDataOutput = function notifyDataOutput(data) {
|
|
762
|
+
var _props$listener11, _props$listener11$onC;
|
|
763
|
+
(_props$listener11 = props.listener) === null || _props$listener11 === void 0 || (_props$listener11$onC = _props$listener11.onChange) === null || _props$listener11$onC === void 0 || _props$listener11$onC.call(_props$listener11, props.name, {
|
|
764
|
+
dataoutput: data
|
|
765
|
+
});
|
|
766
|
+
};
|
|
767
|
+
var executeFormSubmit = /*#__PURE__*/function () {
|
|
768
|
+
var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4(formData, operationType) {
|
|
769
|
+
var firstParam;
|
|
770
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
771
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
772
|
+
case 0:
|
|
773
|
+
firstParam = prepareSubmitData(formData);
|
|
774
|
+
return _context4.abrupt("return", new Promise(function (resolve, reject) {
|
|
775
|
+
props.formSubmit(firstParam, function (data) {
|
|
776
|
+
return handleSubmitSuccess(data, resolve);
|
|
230
777
|
}, function (error) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (props !== null && props !== void 0 && props.onSubmit) {
|
|
236
|
-
props.onSubmit(e, props, FormData);
|
|
237
|
-
}
|
|
238
|
-
case 17:
|
|
778
|
+
return handleSubmitError(error, reject);
|
|
779
|
+
}, operationType);
|
|
780
|
+
}));
|
|
781
|
+
case 2:
|
|
239
782
|
case "end":
|
|
240
|
-
return
|
|
783
|
+
return _context4.stop();
|
|
241
784
|
}
|
|
242
|
-
},
|
|
785
|
+
}, _callee4);
|
|
243
786
|
}));
|
|
244
|
-
return function
|
|
245
|
-
return
|
|
787
|
+
return function executeFormSubmit(_x4, _x5) {
|
|
788
|
+
return _ref4.apply(this, arguments);
|
|
246
789
|
};
|
|
247
790
|
}();
|
|
791
|
+
var prepareSubmitData = function prepareSubmitData(formData) {
|
|
792
|
+
var _props$datasource, _props$datasource$toL;
|
|
793
|
+
if ((props === null || props === void 0 || (_props$datasource = props.datasource) === null || _props$datasource === void 0 || (_props$datasource = _props$datasource.name) === null || _props$datasource === void 0 || (_props$datasource$toL = _props$datasource.toLowerCase) === null || _props$datasource$toL === void 0 ? void 0 : _props$datasource$toL.call(_props$datasource)) !== "crudvariable") {
|
|
794
|
+
return formData;
|
|
795
|
+
}
|
|
796
|
+
var primaryKeys = props.datasource.execute("getPrimaryKey");
|
|
797
|
+
var operation = (0, _utils2.findOperationType)(formData, primaryKeys);
|
|
798
|
+
return {
|
|
799
|
+
inputFields: formData,
|
|
800
|
+
operation: operation === "insert" ? "create" : operation
|
|
801
|
+
};
|
|
802
|
+
};
|
|
803
|
+
var handleSubmitSuccess = function handleSubmitSuccess(data, resolve) {
|
|
804
|
+
var operationType = data.operationType;
|
|
805
|
+
|
|
806
|
+
// Handle live-form reset
|
|
807
|
+
if (props.widgettype === "live-form" && (operationType === "insert" || operationType === "delete")) {
|
|
808
|
+
reset(data);
|
|
809
|
+
setShowViewMode(false);
|
|
810
|
+
}
|
|
811
|
+
onResultCb((0, _get["default"])(data, "params"), "success");
|
|
812
|
+
|
|
813
|
+
// Show success message
|
|
814
|
+
var message = getSuccessMessage(data);
|
|
815
|
+
toggleMessage(true, message, "success");
|
|
816
|
+
resolve(data);
|
|
817
|
+
};
|
|
818
|
+
var getSuccessMessage = function getSuccessMessage(data) {
|
|
819
|
+
if (props.widgettype === "live-form") {
|
|
820
|
+
var operationType = data.operationType;
|
|
821
|
+
return operationType === "insert" && props.insertmessage || operationType === "update" && props.updatemessage || operationType === "delete" && props.deletemessage || props.postmessage;
|
|
822
|
+
}
|
|
823
|
+
return props.postmessage;
|
|
824
|
+
};
|
|
825
|
+
var handleSubmitError = function handleSubmitError(error, reject) {
|
|
826
|
+
var errorMessage = props.errormessage || (error === null || error === void 0 ? void 0 : error.message) || error;
|
|
827
|
+
toggleMessage(true, errorMessage, "error");
|
|
828
|
+
onResultCb(error, "");
|
|
829
|
+
reject(error);
|
|
830
|
+
};
|
|
248
831
|
var formfieldsRef = (0, _react.useRef)(formfields);
|
|
249
|
-
var submit =
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
832
|
+
var submit = (0, _react.useCallback)(/*#__PURE__*/function () {
|
|
833
|
+
var _ref5 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(e) {
|
|
834
|
+
var currentFormValidState, validationMessages, childFormsValid, _props$listener12, data;
|
|
835
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
836
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
837
|
+
case 0:
|
|
838
|
+
e === null || e === void 0 || e.preventDefault();
|
|
839
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
840
|
+
|
|
841
|
+
// Trigger validation and wait for completion
|
|
842
|
+
_context5.next = 4;
|
|
843
|
+
return trigger();
|
|
844
|
+
case 4:
|
|
845
|
+
currentFormValidState = _context5.sent;
|
|
846
|
+
// Build and expose validation messages after validation completes
|
|
847
|
+
validationMessages = buildValidationMessages();
|
|
848
|
+
exposeValidationMessages(validationMessages);
|
|
849
|
+
|
|
850
|
+
// Check child form validation
|
|
851
|
+
if (!formReff.current) {
|
|
852
|
+
_context5.next = 13;
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
_context5.next = 10;
|
|
856
|
+
return formReff.current.validateFieldsOnSubmit();
|
|
857
|
+
case 10:
|
|
858
|
+
_context5.t0 = _context5.sent;
|
|
859
|
+
_context5.next = 14;
|
|
860
|
+
break;
|
|
861
|
+
case 13:
|
|
862
|
+
_context5.t0 = true;
|
|
863
|
+
case 14:
|
|
864
|
+
childFormsValid = _context5.t0;
|
|
865
|
+
if (!(!childFormsValid || !currentFormValidState)) {
|
|
866
|
+
_context5.next = 18;
|
|
867
|
+
break;
|
|
868
|
+
}
|
|
869
|
+
props === null || props === void 0 || (_props$listener12 = props.listener) === null || _props$listener12 === void 0 || _props$listener12.onChange(props.name, {
|
|
870
|
+
valid: false,
|
|
871
|
+
errors: errors,
|
|
872
|
+
validationMessages: validationMessages
|
|
873
|
+
});
|
|
874
|
+
return _context5.abrupt("return", false);
|
|
875
|
+
case 18:
|
|
876
|
+
data = getValues();
|
|
877
|
+
handleFormSubmit(data, new Event("submit"));
|
|
878
|
+
return _context5.abrupt("return", true);
|
|
879
|
+
case 21:
|
|
880
|
+
case "end":
|
|
881
|
+
return _context5.stop();
|
|
882
|
+
}
|
|
883
|
+
}, _callee5);
|
|
884
|
+
}));
|
|
885
|
+
return function (_x6) {
|
|
886
|
+
return _ref5.apply(this, arguments);
|
|
887
|
+
};
|
|
888
|
+
}(), [handleFormSubmit, trigger, buildValidationMessages, exposeValidationMessages, props.name, errors]);
|
|
889
|
+
var deleteEntry = (0, _react.useCallback)(/*#__PURE__*/function () {
|
|
890
|
+
var _ref6 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(e) {
|
|
891
|
+
var isValid, data;
|
|
892
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
893
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
894
|
+
case 0:
|
|
895
|
+
e === null || e === void 0 || e.preventDefault();
|
|
896
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
897
|
+
_context6.next = 4;
|
|
898
|
+
return validateFieldsOnSubmit();
|
|
899
|
+
case 4:
|
|
900
|
+
isValid = _context6.sent;
|
|
901
|
+
if (isValid) {
|
|
902
|
+
data = getValues();
|
|
903
|
+
handleFormSubmit(data, new Event("submit"), "delete");
|
|
904
|
+
}
|
|
905
|
+
case 6:
|
|
906
|
+
case "end":
|
|
907
|
+
return _context6.stop();
|
|
908
|
+
}
|
|
909
|
+
}, _callee6);
|
|
910
|
+
}));
|
|
911
|
+
return function (_x7) {
|
|
912
|
+
return _ref6.apply(this, arguments);
|
|
913
|
+
};
|
|
914
|
+
}(), [handleFormSubmit, validateFieldsOnSubmit]);
|
|
255
915
|
var livefilterFn = props.Livefilter || function () {};
|
|
256
916
|
var filter = handleSubmit(function (data, e) {
|
|
257
|
-
|
|
917
|
+
e === null || e === void 0 || e.preventDefault();
|
|
918
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
919
|
+
var transformedData = (0, _utils.transformRangeFilterData)(data);
|
|
920
|
+
return livefilterFn(transformedData, false, formfieldsRef.current);
|
|
258
921
|
});
|
|
259
922
|
var clearFilter = handleSubmit(function (data, e) {
|
|
923
|
+
e === null || e === void 0 || e.preventDefault();
|
|
924
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
260
925
|
formreset();
|
|
261
|
-
|
|
926
|
+
var transformedData = (0, _utils.transformRangeFilterData)(data);
|
|
927
|
+
livefilterFn(transformedData, true, formfieldsRef.current);
|
|
262
928
|
});
|
|
929
|
+
var highlightInvalidFields = /*#__PURE__*/function () {
|
|
930
|
+
var _ref7 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
|
|
931
|
+
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
932
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
933
|
+
case 0:
|
|
934
|
+
_context7.next = 2;
|
|
935
|
+
return validateFieldsOnSubmit();
|
|
936
|
+
case 2:
|
|
937
|
+
case "end":
|
|
938
|
+
return _context7.stop();
|
|
939
|
+
}
|
|
940
|
+
}, _callee7);
|
|
941
|
+
}));
|
|
942
|
+
return function highlightInvalidFields() {
|
|
943
|
+
return _ref7.apply(this, arguments);
|
|
944
|
+
};
|
|
945
|
+
}();
|
|
946
|
+
var saveAndNew = function saveAndNew() {
|
|
947
|
+
submit();
|
|
948
|
+
reset({});
|
|
949
|
+
};
|
|
950
|
+
var saveAndView = function saveAndView() {
|
|
951
|
+
submit();
|
|
952
|
+
setShowViewMode(true);
|
|
953
|
+
};
|
|
263
954
|
var onResultCb = /*#__PURE__*/function () {
|
|
264
|
-
var
|
|
955
|
+
var _ref8 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(data, status, event) {
|
|
265
956
|
var params;
|
|
266
|
-
return _regenerator["default"].wrap(function
|
|
267
|
-
while (1) switch (
|
|
957
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
|
958
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
268
959
|
case 0:
|
|
269
960
|
params = {
|
|
270
961
|
$event: event,
|
|
@@ -291,12 +982,12 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
291
982
|
}
|
|
292
983
|
case 3:
|
|
293
984
|
case "end":
|
|
294
|
-
return
|
|
985
|
+
return _context8.stop();
|
|
295
986
|
}
|
|
296
|
-
},
|
|
987
|
+
}, _callee8);
|
|
297
988
|
}));
|
|
298
|
-
return function onResultCb(
|
|
299
|
-
return
|
|
989
|
+
return function onResultCb(_x8, _x9, _x0) {
|
|
990
|
+
return _ref8.apply(this, arguments);
|
|
300
991
|
};
|
|
301
992
|
}();
|
|
302
993
|
|
|
@@ -331,6 +1022,9 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
331
1022
|
}, [props.captionwidth, props.captionposition]),
|
|
332
1023
|
captionCls = _useMemo.captionCls,
|
|
333
1024
|
widgetCls = _useMemo.widgetCls;
|
|
1025
|
+
var itemsPerRow = (0, _react.useMemo)(function () {
|
|
1026
|
+
return (0, _listHelpers.getItemsPerRowClass)(props.itemsperrow);
|
|
1027
|
+
}, [props.itemsperrow]);
|
|
334
1028
|
function expandCollapsePanel() {
|
|
335
1029
|
if (props.collapsible) {
|
|
336
1030
|
// flip the active flag
|
|
@@ -341,6 +1035,8 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
341
1035
|
return watch(fieldName);
|
|
342
1036
|
};
|
|
343
1037
|
var ref = {
|
|
1038
|
+
ref: formReff,
|
|
1039
|
+
updateFormData: updateFormData,
|
|
344
1040
|
control: control,
|
|
345
1041
|
watch: watch,
|
|
346
1042
|
registerHeaderAction: registerHeaderAction,
|
|
@@ -353,37 +1049,15 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
353
1049
|
widgetCls: widgetCls,
|
|
354
1050
|
validationtype: props.validationtype,
|
|
355
1051
|
showViewMode: showViewMode,
|
|
356
|
-
formdata: props.formdata,
|
|
357
|
-
getFieldValue: getFieldValue
|
|
1052
|
+
formdata: widgetFormData || childFormData || props.formdata,
|
|
1053
|
+
getFieldValue: getFieldValue,
|
|
1054
|
+
itemsPerRow: itemsPerRow,
|
|
1055
|
+
saveAndNew: saveAndNew,
|
|
1056
|
+
saveAndView: saveAndView,
|
|
1057
|
+
highlightInvalidFields: highlightInvalidFields,
|
|
1058
|
+
resetField: resetField,
|
|
1059
|
+
submitCount: submitCount
|
|
358
1060
|
};
|
|
359
|
-
var formProps = _objectSpread(_objectSpread({}, props), {}, {
|
|
360
|
-
submit: submit,
|
|
361
|
-
formreset: formreset,
|
|
362
|
-
formfields: formfields,
|
|
363
|
-
formWidgets: formfields,
|
|
364
|
-
headerActions: headerActions,
|
|
365
|
-
ref: ref,
|
|
366
|
-
toggleMessage: toggleMessage,
|
|
367
|
-
clearMessage: clearMessage,
|
|
368
|
-
expandCollapsePanel: expandCollapsePanel,
|
|
369
|
-
expanded: expanded,
|
|
370
|
-
showmessage: showmessage,
|
|
371
|
-
statusMessage: statusMessage,
|
|
372
|
-
showViewMode: showViewMode,
|
|
373
|
-
filter: filter,
|
|
374
|
-
clearFilter: clearFilter,
|
|
375
|
-
validateFieldsOnSubmit: validateFieldsOnSubmit,
|
|
376
|
-
valid: isValid,
|
|
377
|
-
errors: errors,
|
|
378
|
-
"delete": deleteEntry,
|
|
379
|
-
cancel: cancel,
|
|
380
|
-
"new": create,
|
|
381
|
-
edit: edit,
|
|
382
|
-
setShowViewMode: setShowViewMode,
|
|
383
|
-
dataoutput: getValues(),
|
|
384
|
-
save: submit,
|
|
385
|
-
reset: reset
|
|
386
|
-
});
|
|
387
1061
|
var conditionalProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, props.target && {
|
|
388
1062
|
target: props.target
|
|
389
1063
|
}), props.method && {
|
|
@@ -402,7 +1076,7 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
402
1076
|
};
|
|
403
1077
|
};
|
|
404
1078
|
formRef.current.validateForm = function () {
|
|
405
|
-
return trigger();
|
|
1079
|
+
return submitCount === 0 ? isValid : trigger();
|
|
406
1080
|
};
|
|
407
1081
|
formRef.current.clearErrors = function () {
|
|
408
1082
|
clearErrors();
|
|
@@ -411,38 +1085,82 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
411
1085
|
return props;
|
|
412
1086
|
};
|
|
413
1087
|
formRef.current.formWidgets = formfields;
|
|
1088
|
+
// Expose validationMessages getter
|
|
1089
|
+
formRef.current.getValidationMessages = function () {
|
|
1090
|
+
return validationMessagesRef.current;
|
|
1091
|
+
};
|
|
1092
|
+
formRef.current.validationMessages = validationMessagesRef.current;
|
|
414
1093
|
}
|
|
415
1094
|
}, [watch, trigger, isValid, errors, formfields]);
|
|
416
1095
|
function create() {
|
|
1096
|
+
formreset();
|
|
417
1097
|
formreset();
|
|
418
1098
|
setShowViewMode(false);
|
|
419
1099
|
}
|
|
420
1100
|
function edit(data) {
|
|
421
1101
|
if (data) {
|
|
422
|
-
|
|
1102
|
+
// Convert null values to empty strings to avoid React Hook Form using old defaultValues
|
|
1103
|
+
var cleanedData = {};
|
|
1104
|
+
Object.keys(data).forEach(function (key) {
|
|
1105
|
+
cleanedData[key] = data[key] === null ? "" : data[key];
|
|
1106
|
+
});
|
|
1107
|
+
reset(cleanedData);
|
|
1108
|
+
// Update the ref to track this as the last reset formdata
|
|
1109
|
+
lastResetFormDataRef.current = cleanedData;
|
|
423
1110
|
}
|
|
424
1111
|
setShowViewMode(false);
|
|
425
1112
|
}
|
|
426
|
-
function
|
|
1113
|
+
function setFormData(data) {
|
|
1114
|
+
var _props$listener13;
|
|
1115
|
+
if (!data || (0, _typeof2["default"])(data) !== "object" || Array.isArray(data)) {
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
var cleanedData = {};
|
|
1119
|
+
Object.keys(data).forEach(function (key) {
|
|
1120
|
+
cleanedData[key] = data[key] === null ? "" : data[key];
|
|
1121
|
+
});
|
|
1122
|
+
reset(cleanedData);
|
|
1123
|
+
// Update the ref to track this as the last reset formdata
|
|
1124
|
+
lastResetFormDataRef.current = cleanedData;
|
|
1125
|
+
if ((_props$listener13 = props.listener) !== null && _props$listener13 !== void 0 && _props$listener13.Widgets && props.name) {
|
|
1126
|
+
props.listener.Widgets[props.name].formdata = cleanedData;
|
|
1127
|
+
}
|
|
1128
|
+
if (props["form-type"] === "live-filter") {
|
|
1129
|
+
debouncedFilter();
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
(0, _react.useEffect)(function () {
|
|
1133
|
+
return function () {
|
|
1134
|
+
var _props$destroy;
|
|
1135
|
+
props === null || props === void 0 || (_props$destroy = props.destroy) === null || _props$destroy === void 0 || _props$destroy.call(props, props.name);
|
|
1136
|
+
formreset();
|
|
1137
|
+
};
|
|
1138
|
+
}, [props.name]);
|
|
1139
|
+
function handleCancel() {
|
|
1140
|
+
if (typeof props.cancel === "function") {
|
|
1141
|
+
props.cancel();
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
427
1144
|
setShowViewMode(true);
|
|
428
1145
|
}
|
|
429
|
-
var fields = (0,
|
|
430
|
-
|
|
1146
|
+
var fields = (0, _react.useMemo)(function () {
|
|
1147
|
+
var _props$listener14;
|
|
431
1148
|
var newFields = [];
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
1149
|
+
var Widgets = ((_props$listener14 = props.listener) === null || _props$listener14 === void 0 || (_props$listener14 = _props$listener14.Widgets) === null || _props$listener14 === void 0 || (_props$listener14 = _props$listener14[props.name]) === null || _props$listener14 === void 0 ? void 0 : _props$listener14.formfields) || {};
|
|
1150
|
+
Object.keys(Widgets).forEach(function (key) {
|
|
1151
|
+
if (!key.includes("formWidget") && Widgets[key]) {
|
|
1152
|
+
newFields.push(Widgets[key]);
|
|
435
1153
|
}
|
|
436
1154
|
});
|
|
437
1155
|
return newFields;
|
|
438
|
-
}, [
|
|
1156
|
+
}, [(_props$listener15 = props.listener) === null || _props$listener15 === void 0 ? void 0 : _props$listener15.Widgets[props.name], props.name]);
|
|
439
1157
|
|
|
440
1158
|
// Call onDataSourceChange when formfields change
|
|
441
1159
|
(0, _react.useEffect)(function () {
|
|
442
|
-
if (props.onDataSourceChange &&
|
|
443
|
-
props.onDataSourceChange(
|
|
1160
|
+
if (props.onDataSourceChange && fields.length > 0) {
|
|
1161
|
+
props.onDataSourceChange(fields);
|
|
444
1162
|
}
|
|
445
|
-
}, [
|
|
1163
|
+
}, [fields, props.onDataSourceChange]);
|
|
446
1164
|
|
|
447
1165
|
// Determine form classes based on wizard context
|
|
448
1166
|
var formClassName = (0, _react.useMemo)(function () {
|
|
@@ -452,8 +1170,18 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
452
1170
|
return (0, _clsx["default"])(DEFAULT_CLASS, props.className);
|
|
453
1171
|
}, [isInsideWizard, props.className]);
|
|
454
1172
|
|
|
455
|
-
//
|
|
1173
|
+
// Keep track of last emitted values to avoid redundant emissions
|
|
1174
|
+
var lastEmittedValuesSerialized = (0, _react.useRef)("");
|
|
1175
|
+
|
|
1176
|
+
// Helper function to reset form with new data
|
|
1177
|
+
var resetFormWithData = function resetFormWithData(newData) {
|
|
1178
|
+
var cleanNulls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1179
|
+
reset(newData);
|
|
1180
|
+
lastResetFormDataRef.current = newData;
|
|
1181
|
+
};
|
|
456
1182
|
(0, _react.useEffect)(function () {
|
|
1183
|
+
// Added for wizard validations please do not remove the blow emit code changes.
|
|
1184
|
+
// Notify parent containers (wizard) about validity changes
|
|
457
1185
|
var el = formRef.current;
|
|
458
1186
|
if (!el) return;
|
|
459
1187
|
var emit = function emit() {
|
|
@@ -465,35 +1193,118 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
465
1193
|
}));
|
|
466
1194
|
};
|
|
467
1195
|
emit();
|
|
468
|
-
var unsubscribe = watch(function () {
|
|
469
|
-
|
|
1196
|
+
var unsubscribe = watch(function (values) {
|
|
1197
|
+
emit();
|
|
1198
|
+
var serialized = JSON.stringify(values);
|
|
1199
|
+
if (serialized !== lastEmittedValuesSerialized.current) {
|
|
1200
|
+
var _props$listener16;
|
|
1201
|
+
lastEmittedValuesSerialized.current = serialized;
|
|
1202
|
+
// For child forms, emit data update event to parent form
|
|
1203
|
+
if (parentForm) {
|
|
1204
|
+
if (isParentList && formArrayIndex >= 0) {
|
|
1205
|
+
// Forms inside lists update array indices in parent form
|
|
1206
|
+
_events.EVENTEMITTER_METHODS.CHILD_FORM_DATA_UPDATE_EMIT(parentForm, {
|
|
1207
|
+
childFormName: props.name,
|
|
1208
|
+
childdatasetnode: effectiveChildDatasetNode,
|
|
1209
|
+
formArrayIndex: formArrayIndex,
|
|
1210
|
+
formData: values,
|
|
1211
|
+
childFormInstance: {
|
|
1212
|
+
getValues: getValues,
|
|
1213
|
+
reset: reset,
|
|
1214
|
+
setFormData: setFormData
|
|
1215
|
+
},
|
|
1216
|
+
isListForm: true
|
|
1217
|
+
});
|
|
1218
|
+
} else if (effectiveChildDatasetNode) {
|
|
1219
|
+
// Regular child forms update object properties
|
|
1220
|
+
_events.EVENTEMITTER_METHODS.CHILD_FORM_DATA_UPDATE_EMIT(parentForm, {
|
|
1221
|
+
childFormName: props.name,
|
|
1222
|
+
childdatasetnode: effectiveChildDatasetNode,
|
|
1223
|
+
formData: values,
|
|
1224
|
+
childFormInstance: {
|
|
1225
|
+
getValues: getValues,
|
|
1226
|
+
reset: reset,
|
|
1227
|
+
setFormData: setFormData
|
|
1228
|
+
},
|
|
1229
|
+
isListForm: false
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
// Emit current form's dataoutput
|
|
1235
|
+
if (props !== null && props !== void 0 && (_props$listener16 = props.listener) !== null && _props$listener16 !== void 0 && _props$listener16.onChange && props !== null && props !== void 0 && props.name) {
|
|
1236
|
+
props.listener.onChange(props.name, {
|
|
1237
|
+
dataoutput: getValues()
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
470
1241
|
});
|
|
471
1242
|
return function () {
|
|
472
1243
|
if (typeof unsubscribe === "function") {
|
|
473
1244
|
unsubscribe();
|
|
474
1245
|
}
|
|
1246
|
+
// Clean up child and parent form event listeners
|
|
1247
|
+
if (childFormUnsubscribeRef.current) {
|
|
1248
|
+
childFormUnsubscribeRef.current();
|
|
1249
|
+
childFormUnsubscribeRef.current = null;
|
|
1250
|
+
}
|
|
1251
|
+
if (parentFormUnsubscribeRef.current) {
|
|
1252
|
+
parentFormUnsubscribeRef.current();
|
|
1253
|
+
parentFormUnsubscribeRef.current = null;
|
|
1254
|
+
}
|
|
475
1255
|
};
|
|
476
|
-
}, [watch, isValid]);
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
1256
|
+
}, [watch, isValid, parentForm, effectiveChildDatasetNode, props.name, props["data-widget-id"]]);
|
|
1257
|
+
var formProps = _objectSpread(_objectSpread(_objectSpread({}, props), conditionalProps), {}, {
|
|
1258
|
+
submit: submit,
|
|
1259
|
+
formreset: formreset,
|
|
1260
|
+
formfields: formfields,
|
|
1261
|
+
formWidgets: formfields,
|
|
1262
|
+
headerActions: headerActions,
|
|
1263
|
+
ref: ref,
|
|
1264
|
+
formElementRef: formRef,
|
|
1265
|
+
toggleMessage: toggleMessage,
|
|
1266
|
+
clearMessage: clearMessage,
|
|
1267
|
+
expandCollapsePanel: expandCollapsePanel,
|
|
1268
|
+
expanded: expanded,
|
|
1269
|
+
showmessage: showmessage,
|
|
1270
|
+
statusMessage: statusMessage,
|
|
1271
|
+
showViewMode: showViewMode,
|
|
1272
|
+
filter: filter,
|
|
1273
|
+
clearFilter: clearFilter,
|
|
1274
|
+
validateFieldsOnSubmit: validateFieldsOnSubmit,
|
|
1275
|
+
errors: errors,
|
|
1276
|
+
validationMessages: validationMessagesRef.current,
|
|
1277
|
+
"delete": deleteEntry,
|
|
1278
|
+
cancel: handleCancel,
|
|
1279
|
+
"new": create,
|
|
1280
|
+
edit: edit,
|
|
1281
|
+
setShowViewMode: setShowViewMode,
|
|
1282
|
+
dataoutput: getValues(),
|
|
1283
|
+
save: submit,
|
|
1284
|
+
setFormData: setFormData,
|
|
1285
|
+
reset: reset,
|
|
482
1286
|
numberoffields: Object.keys(formfields).length,
|
|
483
|
-
ref: formRef,
|
|
484
1287
|
className: formClassName,
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
})
|
|
1288
|
+
saveAndNew: saveAndNew,
|
|
1289
|
+
saveAndView: saveAndView,
|
|
1290
|
+
highlightInvalidFields: highlightInvalidFields,
|
|
1291
|
+
formdata: widgetFormData || childFormData || props.formdata
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
// if parentFormRef is not null, register methods to parent form
|
|
1295
|
+
(0, _react.useImperativeHandle)(parentFormRef, function () {
|
|
1296
|
+
return {
|
|
1297
|
+
formreset: formreset,
|
|
1298
|
+
validateFieldsOnSubmit: validateFieldsOnSubmit
|
|
1299
|
+
};
|
|
1300
|
+
});
|
|
1301
|
+
return __jsx(_formContext.FormProvider, {
|
|
490
1302
|
value: ref,
|
|
491
1303
|
isViewMode: showViewMode
|
|
492
1304
|
}, __jsx(WrappedComponent, (0, _extends2["default"])({}, formProps, {
|
|
493
|
-
valid: isValid,
|
|
494
1305
|
formWidgets: formfields,
|
|
495
1306
|
formfields: formfields
|
|
496
|
-
})))
|
|
1307
|
+
})));
|
|
497
1308
|
};
|
|
498
1309
|
return ControlledForm;
|
|
499
1310
|
};
|