@wavemaker/react-runtime 11.14.2-rc.6311 → 11.15.0-1.246
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 +73 -18
- 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 +31 -11
- 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 +4 -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/repeat-template/index.js +33 -0
- package/components/container/tabs/index.js +83 -14
- package/components/container/tabs/tab-pane/index.js +33 -10
- 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 +985 -183
- 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 +67 -45
- 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 +51 -18
- 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 -52
- 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 +209 -72
- 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 +105 -32
- 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 +85 -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 +41 -3
- 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 +840 -740
- 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$listener14;
|
|
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,395 @@ 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 cleanedData, el;
|
|
448
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
449
|
+
while (1) switch (_context.prev = _context.next) {
|
|
450
|
+
case 0:
|
|
451
|
+
cleanedData = {};
|
|
452
|
+
Object.keys(formfields).forEach(function (key) {
|
|
453
|
+
if (formfields[key].formName !== props.name) return;
|
|
454
|
+
// do not reset for readonly and disabled fields
|
|
455
|
+
if (formfields[key].readonly || formfields[key].readOnly || formfields[key].disabled) {
|
|
456
|
+
cleanedData[key] = formfields[key].defaultvalue || formfields[key].value;
|
|
457
|
+
} else {
|
|
458
|
+
cleanedData[key] = "";
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
_context.next = 4;
|
|
462
|
+
return reset(cleanedData);
|
|
463
|
+
case 4:
|
|
464
|
+
_context.next = 6;
|
|
465
|
+
return reset(cleanedData);
|
|
466
|
+
case 6:
|
|
467
|
+
trigger();
|
|
468
|
+
// dispatching an event for uncontrolled widget like seach widget clear inside the chips widget.
|
|
469
|
+
el = formRef.current;
|
|
470
|
+
if (el) {
|
|
471
|
+
el.dispatchEvent(new CustomEvent("wmformreset", {
|
|
472
|
+
bubbles: true
|
|
473
|
+
}));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Reset all registered child forms
|
|
477
|
+
if (formReff !== null && formReff !== void 0 && formReff.current) {
|
|
478
|
+
Object.values(formReff.current).forEach(function (childForm) {
|
|
479
|
+
var _childForm$formreset;
|
|
480
|
+
return childForm === null || childForm === void 0 || (_childForm$formreset = childForm.formreset) === null || _childForm$formreset === void 0 ? void 0 : _childForm$formreset.call(childForm);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
case 10:
|
|
484
|
+
case "end":
|
|
485
|
+
return _context.stop();
|
|
486
|
+
}
|
|
487
|
+
}, _callee);
|
|
488
|
+
}));
|
|
489
|
+
return function formreset() {
|
|
490
|
+
return _ref.apply(this, arguments);
|
|
491
|
+
};
|
|
492
|
+
}();
|
|
104
493
|
var isElementInViewport = function isElementInViewport(el) {
|
|
105
494
|
if (!el) return false;
|
|
106
495
|
var rect = el.getBoundingClientRect();
|
|
@@ -147,12 +536,13 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
147
536
|
scrollToElement(formEl);
|
|
148
537
|
}
|
|
149
538
|
} else {
|
|
150
|
-
var _props$
|
|
151
|
-
props === null || props === void 0 || (_props$
|
|
539
|
+
var _props$listener8;
|
|
540
|
+
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
541
|
}
|
|
153
542
|
} else {
|
|
154
543
|
setStatusMessage({
|
|
155
|
-
caption: ""
|
|
544
|
+
caption: "",
|
|
545
|
+
type: ""
|
|
156
546
|
});
|
|
157
547
|
setShowMessage(false);
|
|
158
548
|
}
|
|
@@ -160,111 +550,401 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
160
550
|
scrollToElement(formRef.current);
|
|
161
551
|
}
|
|
162
552
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Creates a validation message object for a field with errors.
|
|
556
|
+
* Simplified - only adds entries (array is cleared before each build).
|
|
557
|
+
*/
|
|
558
|
+
var addValidationMessage = (0, _react.useCallback)(function (fieldErrors, fieldKey, field, prefix) {
|
|
559
|
+
var _field$value;
|
|
560
|
+
var errorTypes = (0, _formUtils.getErrorTypes)(fieldErrors);
|
|
561
|
+
validationMessagesRef.current.push({
|
|
562
|
+
field: fieldKey,
|
|
563
|
+
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,
|
|
564
|
+
errorType: errorTypes,
|
|
565
|
+
message: (field === null || field === void 0 ? void 0 : field.validationmessage) || (fieldErrors === null || fieldErrors === void 0 ? void 0 : fieldErrors.message) || "",
|
|
566
|
+
getElement: function getElement() {
|
|
567
|
+
var formEl = formRef.current;
|
|
568
|
+
if (formEl) {
|
|
569
|
+
var fieldEl = formEl.querySelector("[name=\"".concat(fieldKey, "\"]"));
|
|
570
|
+
if (fieldEl) {
|
|
571
|
+
return fieldEl.closest("[focus-target]") || fieldEl.querySelector("[focus-target]") || fieldEl;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return null;
|
|
575
|
+
},
|
|
576
|
+
formName: (0, _lodashEs.last)(prefix.split(".")) || props.name || "",
|
|
577
|
+
fullyQualifiedFormName: prefix
|
|
578
|
+
});
|
|
579
|
+
}, [props.name]);
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Exposes validationMessages on widget object and formRef for external access.
|
|
583
|
+
* DRY helper to avoid repeating this pattern.
|
|
584
|
+
*/
|
|
585
|
+
var exposeValidationMessages = (0, _react.useCallback)(function (validationMessages) {
|
|
586
|
+
var _props$listener9;
|
|
587
|
+
if ((_props$listener9 = props.listener) !== null && _props$listener9 !== void 0 && (_props$listener9 = _props$listener9.Widgets) !== null && _props$listener9 !== void 0 && _props$listener9[props.name]) {
|
|
588
|
+
props.listener.Widgets[props.name].validationMessages = validationMessages;
|
|
589
|
+
}
|
|
590
|
+
if (formRef.current) {
|
|
591
|
+
formRef.current.validationMessages = validationMessages;
|
|
592
|
+
}
|
|
593
|
+
}, [props.name]);
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Gets the form fields to validate and their keys.
|
|
597
|
+
* DRY helper for shared iteration setup.
|
|
598
|
+
*/
|
|
599
|
+
var getFormFieldsForValidation = (0, _react.useCallback)(function () {
|
|
600
|
+
var _props$listener0;
|
|
601
|
+
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;
|
|
602
|
+
var allFieldKeys = Object.keys(formFieldsToValidate);
|
|
603
|
+
var prefix = props.name || "";
|
|
604
|
+
return {
|
|
605
|
+
formFieldsToValidate: formFieldsToValidate,
|
|
606
|
+
allFieldKeys: allFieldKeys,
|
|
607
|
+
prefix: prefix
|
|
608
|
+
};
|
|
609
|
+
}, [props.name, formfields]);
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Core validation messages builder that accepts a getFieldError function.
|
|
613
|
+
* This allows both sync and async validation to share the same iteration logic.
|
|
614
|
+
*/
|
|
615
|
+
var buildValidationMessagesCore = (0, _react.useCallback)(function (getFieldError) {
|
|
616
|
+
validationMessagesRef.current = [];
|
|
617
|
+
var _getFormFieldsForVali = getFormFieldsForValidation(),
|
|
618
|
+
formFieldsToValidate = _getFormFieldsForVali.formFieldsToValidate,
|
|
619
|
+
allFieldKeys = _getFormFieldsForVali.allFieldKeys,
|
|
620
|
+
prefix = _getFormFieldsForVali.prefix;
|
|
621
|
+
allFieldKeys.forEach(function (fieldKey) {
|
|
622
|
+
if ((0, _formUtils.shouldSkipFieldKey)(fieldKey, allFieldKeys)) return;
|
|
623
|
+
var field = formFieldsToValidate[fieldKey];
|
|
624
|
+
var fieldErrors = getFieldError(fieldKey, field);
|
|
625
|
+
if (fieldErrors) {
|
|
626
|
+
addValidationMessage(fieldErrors, fieldKey, field, prefix);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
return validationMessagesRef.current;
|
|
630
|
+
}, [getFormFieldsForValidation, addValidationMessage]);
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Builds validation messages using react-hook-form's state.
|
|
634
|
+
* Uses control.getFieldState() to get error state.
|
|
635
|
+
* Call trigger() before this to ensure validation has run.
|
|
636
|
+
*/
|
|
637
|
+
var buildValidationMessages = (0, _react.useCallback)(function () {
|
|
638
|
+
return buildValidationMessagesCore(function (fieldKey) {
|
|
639
|
+
var fieldState = control.getFieldState(fieldKey);
|
|
640
|
+
return fieldState === null || fieldState === void 0 ? void 0 : fieldState.error;
|
|
641
|
+
});
|
|
642
|
+
}, [buildValidationMessagesCore, control]);
|
|
643
|
+
var validateFieldsOnSubmit = (0, _react.useCallback)(/*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
644
|
+
var isValid, childForms, validationResults, validationMessages, currentFormValidState, _props$listener1;
|
|
645
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
646
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
647
|
+
case 0:
|
|
648
|
+
// Validate all registered child forms
|
|
649
|
+
isValid = true;
|
|
650
|
+
childForms = formReff.current ? Object.values(formReff.current) : [];
|
|
651
|
+
if (!childForms.length) {
|
|
652
|
+
_context2.next = 7;
|
|
653
|
+
break;
|
|
654
|
+
}
|
|
655
|
+
_context2.next = 5;
|
|
656
|
+
return Promise.all(childForms.map(function (childForm) {
|
|
657
|
+
var _childForm$validateFi, _childForm$validateFi2;
|
|
658
|
+
return (_childForm$validateFi = childForm === null || childForm === void 0 || (_childForm$validateFi2 = childForm.validateFieldsOnSubmit) === null || _childForm$validateFi2 === void 0 ? void 0 : _childForm$validateFi2.call(childForm)) !== null && _childForm$validateFi !== void 0 ? _childForm$validateFi : Promise.resolve(true);
|
|
659
|
+
}));
|
|
660
|
+
case 5:
|
|
661
|
+
validationResults = _context2.sent;
|
|
662
|
+
isValid = validationResults.every(Boolean);
|
|
663
|
+
case 7:
|
|
664
|
+
// Build and expose validation messages immediately after trigger
|
|
665
|
+
validationMessages = buildValidationMessages();
|
|
666
|
+
exposeValidationMessages(validationMessages);
|
|
667
|
+
_context2.next = 11;
|
|
668
|
+
return trigger();
|
|
669
|
+
case 11:
|
|
670
|
+
currentFormValidState = _context2.sent;
|
|
671
|
+
if (!(!isValid || !currentFormValidState)) {
|
|
672
|
+
_context2.next = 16;
|
|
673
|
+
break;
|
|
674
|
+
}
|
|
675
|
+
if (!currentFormValidState) {
|
|
676
|
+
props === null || props === void 0 || (_props$listener1 = props.listener) === null || _props$listener1 === void 0 || _props$listener1.onChange(props.name, {
|
|
185
677
|
valid: false,
|
|
186
678
|
errors: errors
|
|
187
679
|
});
|
|
188
|
-
|
|
189
|
-
|
|
680
|
+
}
|
|
681
|
+
(0, _utils.focusOnFirstInvalidField)(formRef.current, Object.keys(errors));
|
|
682
|
+
return _context2.abrupt("return", false);
|
|
683
|
+
case 16:
|
|
684
|
+
return _context2.abrupt("return", true);
|
|
685
|
+
case 17:
|
|
686
|
+
case "end":
|
|
687
|
+
return _context2.stop();
|
|
688
|
+
}
|
|
689
|
+
}, _callee2);
|
|
690
|
+
})), [formReff, trigger, buildValidationMessages, exposeValidationMessages, errors]);
|
|
691
|
+
var updateFormDataOutput = function updateFormDataOutput(data, formWidgets) {
|
|
692
|
+
// Set the values of the widgets inside the live form (other than form fields) in form data
|
|
693
|
+
Object.keys(formWidgets).forEach(function (key) {
|
|
694
|
+
if (!(0, _lodashEs.find)(data, {
|
|
695
|
+
key: key
|
|
696
|
+
})) {
|
|
697
|
+
data[key] = formWidgets[key];
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
return data;
|
|
701
|
+
};
|
|
702
|
+
var handleFormSubmit = /*#__PURE__*/function () {
|
|
703
|
+
var _ref3 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(data, e, operationType) {
|
|
704
|
+
var _props$listener10, _props$onSubmit;
|
|
705
|
+
var formWidgets, filteredData, mergedData, result, formData;
|
|
706
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
707
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
708
|
+
case 0:
|
|
709
|
+
e = e || new Event("submit");
|
|
710
|
+
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;
|
|
711
|
+
if (formWidgets && Object.keys(formWidgets).length > 0) {
|
|
712
|
+
data = updateFormDataOutput(data, formWidgets);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// Filter and merge data
|
|
716
|
+
filteredData = filterTableColumns(data);
|
|
717
|
+
mergedData = mergeWithFormDataRef(filteredData); // Execute onBeforeSubmit hook
|
|
190
718
|
if (!props.onBeforeSubmit) {
|
|
191
|
-
|
|
719
|
+
_context3.next = 11;
|
|
192
720
|
break;
|
|
193
721
|
}
|
|
194
|
-
|
|
195
|
-
return props.onBeforeSubmit(e, props,
|
|
196
|
-
case
|
|
197
|
-
result =
|
|
722
|
+
_context3.next = 8;
|
|
723
|
+
return props.onBeforeSubmit(e, props, mergedData);
|
|
724
|
+
case 8:
|
|
725
|
+
result = _context3.sent;
|
|
198
726
|
if (!(result === false)) {
|
|
199
|
-
|
|
727
|
+
_context3.next = 11;
|
|
200
728
|
break;
|
|
201
729
|
}
|
|
202
|
-
return
|
|
203
|
-
case
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
730
|
+
return _context3.abrupt("return");
|
|
731
|
+
case 11:
|
|
732
|
+
// Transform flat data to nested structure
|
|
733
|
+
formData = transformToNestedObject(mergedData); // Handle form submission
|
|
734
|
+
notifyDataOutput(mergedData);
|
|
735
|
+
_context3.next = 15;
|
|
736
|
+
return executeFormSubmit(formData, operationType);
|
|
737
|
+
case 15:
|
|
738
|
+
// Execute onSubmit hook
|
|
739
|
+
props === null || props === void 0 || (_props$onSubmit = props.onSubmit) === null || _props$onSubmit === void 0 || _props$onSubmit.call(props, e, props, formData);
|
|
740
|
+
case 16:
|
|
741
|
+
case "end":
|
|
742
|
+
return _context3.stop();
|
|
743
|
+
}
|
|
744
|
+
}, _callee3);
|
|
745
|
+
}));
|
|
746
|
+
return function handleFormSubmit(_x, _x2, _x3) {
|
|
747
|
+
return _ref3.apply(this, arguments);
|
|
748
|
+
};
|
|
749
|
+
}();
|
|
216
750
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
751
|
+
// Helper functions
|
|
752
|
+
var filterTableColumns = function filterTableColumns(data) {
|
|
753
|
+
return Object.keys(data).reduce(function (acc, key) {
|
|
754
|
+
if (!key.startsWith("wm_table_column_")) {
|
|
755
|
+
acc[key] = data[key];
|
|
756
|
+
}
|
|
757
|
+
return acc;
|
|
758
|
+
}, {});
|
|
759
|
+
};
|
|
760
|
+
var mergeWithFormDataRef = function mergeWithFormDataRef(data) {
|
|
761
|
+
if (!formDataref.current) return data;
|
|
762
|
+
var merged = _objectSpread({}, data);
|
|
763
|
+
Object.keys(formDataref.current).forEach(function (key) {
|
|
764
|
+
if (formDataref.current.hasOwnProperty(key)) {
|
|
765
|
+
merged[key] = formDataref.current[key] || [];
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
return merged;
|
|
769
|
+
};
|
|
770
|
+
var transformToNestedObject = function transformToNestedObject(data) {
|
|
771
|
+
var result = {};
|
|
772
|
+
Object.keys(data).forEach(function (key) {
|
|
773
|
+
(0, _set["default"])(result, key, data[key]);
|
|
774
|
+
});
|
|
775
|
+
return result;
|
|
776
|
+
};
|
|
777
|
+
var notifyDataOutput = function notifyDataOutput(data) {
|
|
778
|
+
var _props$listener11, _props$listener11$onC;
|
|
779
|
+
(_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, {
|
|
780
|
+
dataoutput: data
|
|
781
|
+
});
|
|
782
|
+
};
|
|
783
|
+
var executeFormSubmit = /*#__PURE__*/function () {
|
|
784
|
+
var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4(formData, operationType) {
|
|
785
|
+
var firstParam;
|
|
786
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
787
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
788
|
+
case 0:
|
|
789
|
+
firstParam = prepareSubmitData(formData);
|
|
790
|
+
return _context4.abrupt("return", new Promise(function (resolve, reject) {
|
|
791
|
+
props.formSubmit(firstParam, function (data) {
|
|
792
|
+
return handleSubmitSuccess(data, resolve);
|
|
230
793
|
}, 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:
|
|
794
|
+
return handleSubmitError(error, reject);
|
|
795
|
+
}, operationType);
|
|
796
|
+
}));
|
|
797
|
+
case 2:
|
|
239
798
|
case "end":
|
|
240
|
-
return
|
|
799
|
+
return _context4.stop();
|
|
241
800
|
}
|
|
242
|
-
},
|
|
801
|
+
}, _callee4);
|
|
243
802
|
}));
|
|
244
|
-
return function
|
|
245
|
-
return
|
|
803
|
+
return function executeFormSubmit(_x4, _x5) {
|
|
804
|
+
return _ref4.apply(this, arguments);
|
|
246
805
|
};
|
|
247
806
|
}();
|
|
807
|
+
var prepareSubmitData = function prepareSubmitData(formData) {
|
|
808
|
+
var _props$datasource, _props$datasource$toL;
|
|
809
|
+
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") {
|
|
810
|
+
return formData;
|
|
811
|
+
}
|
|
812
|
+
var primaryKeys = props.datasource.execute("getPrimaryKey");
|
|
813
|
+
var operation = (0, _utils2.findOperationType)(formData, primaryKeys);
|
|
814
|
+
return {
|
|
815
|
+
inputFields: formData,
|
|
816
|
+
operation: operation === "insert" ? "create" : operation
|
|
817
|
+
};
|
|
818
|
+
};
|
|
819
|
+
var handleSubmitSuccess = function handleSubmitSuccess(data, resolve) {
|
|
820
|
+
var operationType = data.operationType;
|
|
821
|
+
|
|
822
|
+
// Handle live-form reset
|
|
823
|
+
if (props.widgettype === "live-form" && (operationType === "insert" || operationType === "delete")) {
|
|
824
|
+
reset(data);
|
|
825
|
+
setShowViewMode(false);
|
|
826
|
+
}
|
|
827
|
+
onResultCb((0, _get["default"])(data, "params"), "success");
|
|
828
|
+
|
|
829
|
+
// Show success message
|
|
830
|
+
var message = getSuccessMessage(data);
|
|
831
|
+
toggleMessage(true, message, "success");
|
|
832
|
+
resolve(data);
|
|
833
|
+
};
|
|
834
|
+
var getSuccessMessage = function getSuccessMessage(data) {
|
|
835
|
+
if (props.widgettype === "live-form") {
|
|
836
|
+
var operationType = data.operationType;
|
|
837
|
+
return operationType === "insert" && props.insertmessage || operationType === "update" && props.updatemessage || operationType === "delete" && props.deletemessage || props.postmessage;
|
|
838
|
+
}
|
|
839
|
+
return props.postmessage;
|
|
840
|
+
};
|
|
841
|
+
var handleSubmitError = function handleSubmitError(error, reject) {
|
|
842
|
+
var errorMessage = props.errormessage || (error === null || error === void 0 ? void 0 : error.message) || error;
|
|
843
|
+
onResultCb(errorMessage, "");
|
|
844
|
+
reject(error);
|
|
845
|
+
};
|
|
248
846
|
var formfieldsRef = (0, _react.useRef)(formfields);
|
|
249
|
-
var submit =
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
847
|
+
var submit = (0, _react.useCallback)(/*#__PURE__*/function () {
|
|
848
|
+
var _ref5 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(e) {
|
|
849
|
+
var valid, data;
|
|
850
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
851
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
852
|
+
case 0:
|
|
853
|
+
e === null || e === void 0 || e.preventDefault();
|
|
854
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
855
|
+
_context5.next = 4;
|
|
856
|
+
return validateFieldsOnSubmit();
|
|
857
|
+
case 4:
|
|
858
|
+
valid = _context5.sent;
|
|
859
|
+
if (valid) {
|
|
860
|
+
_context5.next = 7;
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
return _context5.abrupt("return");
|
|
864
|
+
case 7:
|
|
865
|
+
data = getValues();
|
|
866
|
+
handleFormSubmit(data, new Event("submit"));
|
|
867
|
+
return _context5.abrupt("return", true);
|
|
868
|
+
case 10:
|
|
869
|
+
case "end":
|
|
870
|
+
return _context5.stop();
|
|
871
|
+
}
|
|
872
|
+
}, _callee5);
|
|
873
|
+
}));
|
|
874
|
+
return function (_x6) {
|
|
875
|
+
return _ref5.apply(this, arguments);
|
|
876
|
+
};
|
|
877
|
+
}(), [handleFormSubmit, validateFieldsOnSubmit]);
|
|
878
|
+
var deleteEntry = (0, _react.useCallback)(/*#__PURE__*/function () {
|
|
879
|
+
var _ref6 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(e) {
|
|
880
|
+
var isValid, data;
|
|
881
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
882
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
883
|
+
case 0:
|
|
884
|
+
e === null || e === void 0 || e.preventDefault();
|
|
885
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
886
|
+
_context6.next = 4;
|
|
887
|
+
return validateFieldsOnSubmit();
|
|
888
|
+
case 4:
|
|
889
|
+
isValid = _context6.sent;
|
|
890
|
+
if (isValid) {
|
|
891
|
+
data = getValues();
|
|
892
|
+
handleFormSubmit(data, new Event("submit"), "delete");
|
|
893
|
+
}
|
|
894
|
+
case 6:
|
|
895
|
+
case "end":
|
|
896
|
+
return _context6.stop();
|
|
897
|
+
}
|
|
898
|
+
}, _callee6);
|
|
899
|
+
}));
|
|
900
|
+
return function (_x7) {
|
|
901
|
+
return _ref6.apply(this, arguments);
|
|
902
|
+
};
|
|
903
|
+
}(), [handleFormSubmit, validateFieldsOnSubmit]);
|
|
255
904
|
var livefilterFn = props.Livefilter || function () {};
|
|
256
905
|
var filter = handleSubmit(function (data, e) {
|
|
257
|
-
|
|
906
|
+
e === null || e === void 0 || e.preventDefault();
|
|
907
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
908
|
+
var transformedData = (0, _utils.transformRangeFilterData)(data);
|
|
909
|
+
return livefilterFn(transformedData, false, formfieldsRef.current);
|
|
258
910
|
});
|
|
259
911
|
var clearFilter = handleSubmit(function (data, e) {
|
|
912
|
+
e === null || e === void 0 || e.preventDefault();
|
|
913
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
260
914
|
formreset();
|
|
261
|
-
|
|
915
|
+
var transformedData = (0, _utils.transformRangeFilterData)(data);
|
|
916
|
+
livefilterFn(transformedData, true, formfieldsRef.current);
|
|
262
917
|
});
|
|
918
|
+
var highlightInvalidFields = /*#__PURE__*/function () {
|
|
919
|
+
var _ref7 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
|
|
920
|
+
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
921
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
922
|
+
case 0:
|
|
923
|
+
_context7.next = 2;
|
|
924
|
+
return validateFieldsOnSubmit();
|
|
925
|
+
case 2:
|
|
926
|
+
case "end":
|
|
927
|
+
return _context7.stop();
|
|
928
|
+
}
|
|
929
|
+
}, _callee7);
|
|
930
|
+
}));
|
|
931
|
+
return function highlightInvalidFields() {
|
|
932
|
+
return _ref7.apply(this, arguments);
|
|
933
|
+
};
|
|
934
|
+
}();
|
|
935
|
+
var saveAndNew = function saveAndNew() {
|
|
936
|
+
submit();
|
|
937
|
+
reset({});
|
|
938
|
+
};
|
|
939
|
+
var saveAndView = function saveAndView() {
|
|
940
|
+
submit();
|
|
941
|
+
setShowViewMode(true);
|
|
942
|
+
};
|
|
263
943
|
var onResultCb = /*#__PURE__*/function () {
|
|
264
|
-
var
|
|
265
|
-
var params;
|
|
266
|
-
return _regenerator["default"].wrap(function
|
|
267
|
-
while (1) switch (
|
|
944
|
+
var _ref8 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(data, status, event) {
|
|
945
|
+
var params, errorMessage;
|
|
946
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
|
947
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
268
948
|
case 0:
|
|
269
949
|
params = {
|
|
270
950
|
$event: event,
|
|
@@ -286,17 +966,18 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
286
966
|
// if service call fails call this method
|
|
287
967
|
props.onError(event, props, data);
|
|
288
968
|
if (props.messagelayout === "Inline") {
|
|
289
|
-
|
|
969
|
+
errorMessage = formProps.errormessage || data || props.errormessage;
|
|
970
|
+
toggleMessage(true, errorMessage, "error");
|
|
290
971
|
}
|
|
291
972
|
}
|
|
292
973
|
case 3:
|
|
293
974
|
case "end":
|
|
294
|
-
return
|
|
975
|
+
return _context8.stop();
|
|
295
976
|
}
|
|
296
|
-
},
|
|
977
|
+
}, _callee8);
|
|
297
978
|
}));
|
|
298
|
-
return function onResultCb(
|
|
299
|
-
return
|
|
979
|
+
return function onResultCb(_x8, _x9, _x0) {
|
|
980
|
+
return _ref8.apply(this, arguments);
|
|
300
981
|
};
|
|
301
982
|
}();
|
|
302
983
|
|
|
@@ -331,6 +1012,9 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
331
1012
|
}, [props.captionwidth, props.captionposition]),
|
|
332
1013
|
captionCls = _useMemo.captionCls,
|
|
333
1014
|
widgetCls = _useMemo.widgetCls;
|
|
1015
|
+
var itemsPerRow = (0, _react.useMemo)(function () {
|
|
1016
|
+
return (0, _listHelpers.getItemsPerRowClass)(props.itemsperrow);
|
|
1017
|
+
}, [props.itemsperrow]);
|
|
334
1018
|
function expandCollapsePanel() {
|
|
335
1019
|
if (props.collapsible) {
|
|
336
1020
|
// flip the active flag
|
|
@@ -341,6 +1025,8 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
341
1025
|
return watch(fieldName);
|
|
342
1026
|
};
|
|
343
1027
|
var ref = {
|
|
1028
|
+
ref: formReff,
|
|
1029
|
+
updateFormData: updateFormData,
|
|
344
1030
|
control: control,
|
|
345
1031
|
watch: watch,
|
|
346
1032
|
registerHeaderAction: registerHeaderAction,
|
|
@@ -353,37 +1039,15 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
353
1039
|
widgetCls: widgetCls,
|
|
354
1040
|
validationtype: props.validationtype,
|
|
355
1041
|
showViewMode: showViewMode,
|
|
356
|
-
formdata: props.formdata,
|
|
357
|
-
getFieldValue: getFieldValue
|
|
1042
|
+
formdata: widgetFormData || childFormData || props.formdata,
|
|
1043
|
+
getFieldValue: getFieldValue,
|
|
1044
|
+
itemsPerRow: itemsPerRow,
|
|
1045
|
+
saveAndNew: saveAndNew,
|
|
1046
|
+
saveAndView: saveAndView,
|
|
1047
|
+
highlightInvalidFields: highlightInvalidFields,
|
|
1048
|
+
resetField: resetField,
|
|
1049
|
+
submitCount: submitCount
|
|
358
1050
|
};
|
|
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
1051
|
var conditionalProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, props.target && {
|
|
388
1052
|
target: props.target
|
|
389
1053
|
}), props.method && {
|
|
@@ -402,7 +1066,7 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
402
1066
|
};
|
|
403
1067
|
};
|
|
404
1068
|
formRef.current.validateForm = function () {
|
|
405
|
-
return trigger();
|
|
1069
|
+
return submitCount === 0 ? isValid : trigger();
|
|
406
1070
|
};
|
|
407
1071
|
formRef.current.clearErrors = function () {
|
|
408
1072
|
clearErrors();
|
|
@@ -411,38 +1075,82 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
411
1075
|
return props;
|
|
412
1076
|
};
|
|
413
1077
|
formRef.current.formWidgets = formfields;
|
|
1078
|
+
// Expose validationMessages getter
|
|
1079
|
+
formRef.current.getValidationMessages = function () {
|
|
1080
|
+
return validationMessagesRef.current;
|
|
1081
|
+
};
|
|
1082
|
+
formRef.current.validationMessages = validationMessagesRef.current;
|
|
414
1083
|
}
|
|
415
1084
|
}, [watch, trigger, isValid, errors, formfields]);
|
|
416
1085
|
function create() {
|
|
1086
|
+
formreset();
|
|
417
1087
|
formreset();
|
|
418
1088
|
setShowViewMode(false);
|
|
419
1089
|
}
|
|
420
1090
|
function edit(data) {
|
|
421
1091
|
if (data) {
|
|
422
|
-
|
|
1092
|
+
// Convert null values to empty strings to avoid React Hook Form using old defaultValues
|
|
1093
|
+
var cleanedData = {};
|
|
1094
|
+
Object.keys(data).forEach(function (key) {
|
|
1095
|
+
cleanedData[key] = data[key] === null ? "" : data[key];
|
|
1096
|
+
});
|
|
1097
|
+
reset(cleanedData);
|
|
1098
|
+
// Update the ref to track this as the last reset formdata
|
|
1099
|
+
lastResetFormDataRef.current = cleanedData;
|
|
423
1100
|
}
|
|
424
1101
|
setShowViewMode(false);
|
|
425
1102
|
}
|
|
426
|
-
function
|
|
1103
|
+
function setFormData(data) {
|
|
1104
|
+
var _props$listener12;
|
|
1105
|
+
if (!data || (0, _typeof2["default"])(data) !== "object" || Array.isArray(data)) {
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
var cleanedData = {};
|
|
1109
|
+
Object.keys(data).forEach(function (key) {
|
|
1110
|
+
cleanedData[key] = data[key] === null ? "" : data[key];
|
|
1111
|
+
});
|
|
1112
|
+
reset(cleanedData);
|
|
1113
|
+
// Update the ref to track this as the last reset formdata
|
|
1114
|
+
lastResetFormDataRef.current = cleanedData;
|
|
1115
|
+
if ((_props$listener12 = props.listener) !== null && _props$listener12 !== void 0 && _props$listener12.Widgets && props.name) {
|
|
1116
|
+
props.listener.Widgets[props.name].formdata = cleanedData;
|
|
1117
|
+
}
|
|
1118
|
+
if (props["form-type"] === "live-filter") {
|
|
1119
|
+
debouncedFilter();
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
(0, _react.useEffect)(function () {
|
|
1123
|
+
return function () {
|
|
1124
|
+
var _props$destroy;
|
|
1125
|
+
props === null || props === void 0 || (_props$destroy = props.destroy) === null || _props$destroy === void 0 || _props$destroy.call(props, props.name);
|
|
1126
|
+
formreset();
|
|
1127
|
+
};
|
|
1128
|
+
}, [props.name]);
|
|
1129
|
+
function handleCancel() {
|
|
1130
|
+
if (typeof props.cancel === "function") {
|
|
1131
|
+
props.cancel();
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
427
1134
|
setShowViewMode(true);
|
|
428
1135
|
}
|
|
429
|
-
var fields = (0,
|
|
430
|
-
|
|
1136
|
+
var fields = (0, _react.useMemo)(function () {
|
|
1137
|
+
var _props$listener13;
|
|
431
1138
|
var newFields = [];
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
1139
|
+
var Widgets = ((_props$listener13 = props.listener) === null || _props$listener13 === void 0 || (_props$listener13 = _props$listener13.Widgets) === null || _props$listener13 === void 0 || (_props$listener13 = _props$listener13[props.name]) === null || _props$listener13 === void 0 ? void 0 : _props$listener13.formfields) || {};
|
|
1140
|
+
Object.keys(Widgets).forEach(function (key) {
|
|
1141
|
+
if (!key.includes("formWidget") && Widgets[key]) {
|
|
1142
|
+
newFields.push(Widgets[key]);
|
|
435
1143
|
}
|
|
436
1144
|
});
|
|
437
1145
|
return newFields;
|
|
438
|
-
}, [
|
|
1146
|
+
}, [(_props$listener14 = props.listener) === null || _props$listener14 === void 0 ? void 0 : _props$listener14.Widgets[props.name], props.name]);
|
|
439
1147
|
|
|
440
1148
|
// Call onDataSourceChange when formfields change
|
|
441
1149
|
(0, _react.useEffect)(function () {
|
|
442
|
-
if (props.onDataSourceChange &&
|
|
443
|
-
props.onDataSourceChange(
|
|
1150
|
+
if (props.onDataSourceChange && fields.length > 0) {
|
|
1151
|
+
props.onDataSourceChange(fields);
|
|
444
1152
|
}
|
|
445
|
-
}, [
|
|
1153
|
+
}, [fields, props.onDataSourceChange]);
|
|
446
1154
|
|
|
447
1155
|
// Determine form classes based on wizard context
|
|
448
1156
|
var formClassName = (0, _react.useMemo)(function () {
|
|
@@ -452,8 +1160,18 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
452
1160
|
return (0, _clsx["default"])(DEFAULT_CLASS, props.className);
|
|
453
1161
|
}, [isInsideWizard, props.className]);
|
|
454
1162
|
|
|
455
|
-
//
|
|
1163
|
+
// Keep track of last emitted values to avoid redundant emissions
|
|
1164
|
+
var lastEmittedValuesSerialized = (0, _react.useRef)("");
|
|
1165
|
+
|
|
1166
|
+
// Helper function to reset form with new data
|
|
1167
|
+
var resetFormWithData = function resetFormWithData(newData) {
|
|
1168
|
+
var cleanNulls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1169
|
+
reset(newData);
|
|
1170
|
+
lastResetFormDataRef.current = newData;
|
|
1171
|
+
};
|
|
456
1172
|
(0, _react.useEffect)(function () {
|
|
1173
|
+
// Added for wizard validations please do not remove the blow emit code changes.
|
|
1174
|
+
// Notify parent containers (wizard) about validity changes
|
|
457
1175
|
var el = formRef.current;
|
|
458
1176
|
if (!el) return;
|
|
459
1177
|
var emit = function emit() {
|
|
@@ -465,35 +1183,119 @@ var BaseForm = function BaseForm(WrappedComponent) {
|
|
|
465
1183
|
}));
|
|
466
1184
|
};
|
|
467
1185
|
emit();
|
|
468
|
-
var unsubscribe = watch(function () {
|
|
469
|
-
|
|
1186
|
+
var unsubscribe = watch(function (values) {
|
|
1187
|
+
emit();
|
|
1188
|
+
var serialized = JSON.stringify(values);
|
|
1189
|
+
if (serialized !== lastEmittedValuesSerialized.current) {
|
|
1190
|
+
var _props$listener15;
|
|
1191
|
+
lastEmittedValuesSerialized.current = serialized;
|
|
1192
|
+
// For child forms, emit data update event to parent form
|
|
1193
|
+
if (parentForm) {
|
|
1194
|
+
if (isParentList && formArrayIndex >= 0) {
|
|
1195
|
+
// Forms inside lists update array indices in parent form
|
|
1196
|
+
_events.EVENTEMITTER_METHODS.CHILD_FORM_DATA_UPDATE_EMIT(parentForm, {
|
|
1197
|
+
childFormName: props.name,
|
|
1198
|
+
childdatasetnode: effectiveChildDatasetNode,
|
|
1199
|
+
formArrayIndex: formArrayIndex,
|
|
1200
|
+
formData: values,
|
|
1201
|
+
childFormInstance: {
|
|
1202
|
+
getValues: getValues,
|
|
1203
|
+
reset: reset,
|
|
1204
|
+
setFormData: setFormData
|
|
1205
|
+
},
|
|
1206
|
+
isListForm: true
|
|
1207
|
+
});
|
|
1208
|
+
} else if (effectiveChildDatasetNode) {
|
|
1209
|
+
// Regular child forms update object properties
|
|
1210
|
+
_events.EVENTEMITTER_METHODS.CHILD_FORM_DATA_UPDATE_EMIT(parentForm, {
|
|
1211
|
+
childFormName: props.name,
|
|
1212
|
+
childdatasetnode: effectiveChildDatasetNode,
|
|
1213
|
+
formData: values,
|
|
1214
|
+
childFormInstance: {
|
|
1215
|
+
getValues: getValues,
|
|
1216
|
+
reset: reset,
|
|
1217
|
+
setFormData: setFormData
|
|
1218
|
+
},
|
|
1219
|
+
isListForm: false
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// Emit current form's dataoutput
|
|
1225
|
+
if (props !== null && props !== void 0 && (_props$listener15 = props.listener) !== null && _props$listener15 !== void 0 && _props$listener15.onChange && props !== null && props !== void 0 && props.name) {
|
|
1226
|
+
props.listener.onChange(props.name, {
|
|
1227
|
+
dataoutput: getValues()
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
470
1231
|
});
|
|
471
1232
|
return function () {
|
|
472
1233
|
if (typeof unsubscribe === "function") {
|
|
473
1234
|
unsubscribe();
|
|
474
1235
|
}
|
|
1236
|
+
// Clean up child and parent form event listeners
|
|
1237
|
+
if (childFormUnsubscribeRef.current) {
|
|
1238
|
+
childFormUnsubscribeRef.current();
|
|
1239
|
+
childFormUnsubscribeRef.current = null;
|
|
1240
|
+
}
|
|
1241
|
+
if (parentFormUnsubscribeRef.current) {
|
|
1242
|
+
parentFormUnsubscribeRef.current();
|
|
1243
|
+
parentFormUnsubscribeRef.current = null;
|
|
1244
|
+
}
|
|
475
1245
|
};
|
|
476
|
-
}, [watch, isValid]);
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
1246
|
+
}, [watch, isValid, parentForm, effectiveChildDatasetNode, props.name, props["data-widget-id"]]);
|
|
1247
|
+
var formProps = _objectSpread(_objectSpread(_objectSpread({}, props), conditionalProps), {}, {
|
|
1248
|
+
submit: submit,
|
|
1249
|
+
formreset: formreset,
|
|
1250
|
+
formfields: formfields,
|
|
1251
|
+
formWidgets: formfields,
|
|
1252
|
+
headerActions: headerActions,
|
|
1253
|
+
ref: ref,
|
|
1254
|
+
formElementRef: formRef,
|
|
1255
|
+
toggleMessage: toggleMessage,
|
|
1256
|
+
clearMessage: clearMessage,
|
|
1257
|
+
expandCollapsePanel: expandCollapsePanel,
|
|
1258
|
+
expanded: expanded,
|
|
1259
|
+
showmessage: showmessage,
|
|
1260
|
+
statusMessage: statusMessage,
|
|
1261
|
+
showViewMode: showViewMode,
|
|
1262
|
+
filter: filter,
|
|
1263
|
+
clearFilter: clearFilter,
|
|
1264
|
+
validateFieldsOnSubmit: validateFieldsOnSubmit,
|
|
1265
|
+
errors: errors,
|
|
1266
|
+
validationMessages: validationMessagesRef.current,
|
|
1267
|
+
"delete": deleteEntry,
|
|
1268
|
+
cancel: handleCancel,
|
|
1269
|
+
"new": create,
|
|
1270
|
+
edit: edit,
|
|
1271
|
+
setShowViewMode: setShowViewMode,
|
|
1272
|
+
dataoutput: getValues(),
|
|
1273
|
+
save: submit,
|
|
1274
|
+
setFormData: setFormData,
|
|
1275
|
+
reset: reset,
|
|
482
1276
|
numberoffields: Object.keys(formfields).length,
|
|
483
|
-
ref: formRef,
|
|
484
1277
|
className: formClassName,
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
})
|
|
1278
|
+
saveAndNew: saveAndNew,
|
|
1279
|
+
saveAndView: saveAndView,
|
|
1280
|
+
highlightInvalidFields: highlightInvalidFields,
|
|
1281
|
+
formdata: widgetFormData || childFormData || props.formdata
|
|
1282
|
+
});
|
|
1283
|
+
|
|
1284
|
+
// if parentFormRef is not null, register methods to parent form with form name as key
|
|
1285
|
+
(0, _react.useImperativeHandle)(parentFormRef, function () {
|
|
1286
|
+
var existing = (parentFormRef === null || parentFormRef === void 0 ? void 0 : parentFormRef.current) || {};
|
|
1287
|
+
return _objectSpread(_objectSpread({}, existing), {}, (0, _defineProperty2["default"])({}, props.name, {
|
|
1288
|
+
formreset: formreset,
|
|
1289
|
+
validateFieldsOnSubmit: validateFieldsOnSubmit
|
|
1290
|
+
}));
|
|
1291
|
+
}, [props.name, formreset, validateFieldsOnSubmit]);
|
|
1292
|
+
return __jsx(_formContext.FormProvider, {
|
|
490
1293
|
value: ref,
|
|
491
1294
|
isViewMode: showViewMode
|
|
492
1295
|
}, __jsx(WrappedComponent, (0, _extends2["default"])({}, formProps, {
|
|
493
|
-
valid: isValid,
|
|
494
1296
|
formWidgets: formfields,
|
|
495
1297
|
formfields: formfields
|
|
496
|
-
})))
|
|
1298
|
+
})));
|
|
497
1299
|
};
|
|
498
1300
|
return ControlledForm;
|
|
499
1301
|
};
|