@zengenti/contensis-react-base 3.0.2-beta.16 → 3.0.2-beta.17
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/cjs/forms.js +49 -64
- package/cjs/forms.js.map +1 -1
- package/esm/forms.js +50 -65
- package/esm/forms.js.map +1 -1
- package/package.json +1 -1
package/cjs/forms.js
CHANGED
|
@@ -563,7 +563,9 @@ const getFieldType = field => {
|
|
|
563
563
|
}
|
|
564
564
|
};
|
|
565
565
|
|
|
566
|
-
const sagas = [effects.takeEvery(SUBMIT_FORM_SUCCESS, onFormSuccess), effects.takeEvery(SUBMIT_FORM_FOR_VALIDATION, doValidateForm), effects.takeEvery(SUBMIT_FORM, onSubmitForm), effects.takeEvery(SET_FORM_ID, doFetchForm),
|
|
566
|
+
const sagas = [effects.takeEvery(SUBMIT_FORM_SUCCESS, onFormSuccess), effects.takeEvery(SUBMIT_FORM_FOR_VALIDATION, doValidateForm), effects.takeEvery(SUBMIT_FORM, onSubmitForm), effects.takeEvery(SET_FORM_ID, doFetchForm),
|
|
567
|
+
// takeLatest(VALIDATE_FIELD, onValidateField),
|
|
568
|
+
effects.takeEvery(PAGE_FORWARD, doTogglePage), effects.takeEvery(PAGE_BACK, doTogglePage), effects.takeEvery(SET_FORM_DATA, getEntryPickerData), effects.takeLatest(SET_FORM_DATA, setDefaultValueFields)];
|
|
567
569
|
function* doValidateForm(action) {
|
|
568
570
|
const {
|
|
569
571
|
formId
|
|
@@ -574,35 +576,31 @@ function* doValidateForm(action) {
|
|
|
574
576
|
formId
|
|
575
577
|
});
|
|
576
578
|
}
|
|
577
|
-
function* onValidateField
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if ((value === null || value === void 0 ? void 0 : value.length) >= 1) yield effects.call(onValidateSingleField, formId, id, value);
|
|
584
|
-
}
|
|
585
|
-
function* validateGroupfields(formId, groupId) {
|
|
579
|
+
// function* onValidateField(action) {
|
|
580
|
+
// const { formId, id, value } = action;
|
|
581
|
+
// if (value?.length >= 1) yield call(onValidateSingleField, formId, id, value);
|
|
582
|
+
// }
|
|
583
|
+
|
|
584
|
+
function* onValidateGroupFields(formId, groupId) {
|
|
586
585
|
const state = yield effects.select();
|
|
587
586
|
const selectPostData = makeSelectFormPostData(formId);
|
|
588
587
|
const postData = selectPostData(state);
|
|
589
588
|
const selectFormFields = makeSelectFormFields(formId);
|
|
590
589
|
const fields = selectFormFields(state);
|
|
591
|
-
const groupFields = fields.filter(f => f.
|
|
592
|
-
let
|
|
590
|
+
const groupFields = fields.filter(f => f.groupId == groupId);
|
|
591
|
+
let errors = [];
|
|
593
592
|
groupFields.forEach(field => {
|
|
594
|
-
let
|
|
595
|
-
if (postData[field.id])
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
const err = doValidateField(field, val);
|
|
599
|
-
if (err) newErrors.push(err);
|
|
593
|
+
let value = '';
|
|
594
|
+
if (postData[field.id]) value = postData[field.id];
|
|
595
|
+
const error = doValidateField(field, value);
|
|
596
|
+
if (error) errors.push(error);
|
|
600
597
|
});
|
|
601
598
|
yield effects.put({
|
|
602
599
|
type: SET_FIELD_ERROR,
|
|
603
600
|
formId: formId,
|
|
604
|
-
value:
|
|
601
|
+
value: errors
|
|
605
602
|
});
|
|
603
|
+
return errors;
|
|
606
604
|
}
|
|
607
605
|
function* onValidateAllFields(formId) {
|
|
608
606
|
const state = yield effects.select();
|
|
@@ -610,42 +608,17 @@ function* onValidateAllFields(formId) {
|
|
|
610
608
|
const postData = selectPostData(state);
|
|
611
609
|
const selectFormFields = makeSelectFormFields(formId);
|
|
612
610
|
const fields = selectFormFields(state);
|
|
613
|
-
|
|
611
|
+
const errors = [];
|
|
614
612
|
fields.forEach(field => {
|
|
615
|
-
let
|
|
616
|
-
if (postData[field.id])
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
const err = doValidateField(field, val);
|
|
620
|
-
if (err) newErrors.push(err);
|
|
613
|
+
let value = '';
|
|
614
|
+
if (postData[field.id]) value = postData[field.id];
|
|
615
|
+
const error = doValidateField(field, value);
|
|
616
|
+
if (error) errors.push(error);
|
|
621
617
|
});
|
|
622
618
|
yield effects.put({
|
|
623
619
|
type: SET_FIELD_ERROR,
|
|
624
620
|
formId: formId,
|
|
625
|
-
value:
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
function* onValidateSingleField(formId, fieldId, value) {
|
|
629
|
-
const state = yield effects.select();
|
|
630
|
-
const selectFormFields = makeSelectFormFields(formId);
|
|
631
|
-
const fields = selectFormFields(state);
|
|
632
|
-
const selectFormFieldErrors = makeSelectFormFieldErrors(formId);
|
|
633
|
-
const errors = selectFormFieldErrors(state);
|
|
634
|
-
const fieldData = fields.find(f => f.id == fieldId);
|
|
635
|
-
const newErrors = [];
|
|
636
|
-
//loop through current errors to remove any of the item we currently edit
|
|
637
|
-
errors.forEach(error => {
|
|
638
|
-
if (error.fieldId !== fieldId) {
|
|
639
|
-
//push any existing errors to new array
|
|
640
|
-
newErrors.push(error);
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
const err = doValidateField(fieldData, value);
|
|
644
|
-
if (err) newErrors.push(err);
|
|
645
|
-
yield effects.put({
|
|
646
|
-
type: SET_FIELD_ERROR,
|
|
647
|
-
formId: formId,
|
|
648
|
-
value: newErrors
|
|
621
|
+
value: errors
|
|
649
622
|
});
|
|
650
623
|
}
|
|
651
624
|
function* doTogglePage(action) {
|
|
@@ -657,15 +630,25 @@ function* doTogglePage(action) {
|
|
|
657
630
|
const selectFormGroups = makeSelectFormGroup(formId);
|
|
658
631
|
const formGroups = selectFormGroups(state);
|
|
659
632
|
if (action.type === PAGE_FORWARD) {
|
|
660
|
-
yield
|
|
633
|
+
const errors = yield onValidateGroupFields(formId, formGroups[pageIndex - 1].id);
|
|
634
|
+
if (errors && errors.length <= 0) {
|
|
635
|
+
yield effects.put({
|
|
636
|
+
type: SET_CURRENT_PAGE,
|
|
637
|
+
formId: formId,
|
|
638
|
+
pageId: formGroups[pageIndex].id,
|
|
639
|
+
pageCount: formGroups.length,
|
|
640
|
+
pageIndex: pageIndex
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
} else if (action.type === PAGE_BACK) {
|
|
644
|
+
yield effects.put({
|
|
645
|
+
type: SET_CURRENT_PAGE,
|
|
646
|
+
formId: formId,
|
|
647
|
+
pageId: formGroups[pageIndex].id,
|
|
648
|
+
pageCount: formGroups.length,
|
|
649
|
+
pageIndex: pageIndex
|
|
650
|
+
});
|
|
661
651
|
}
|
|
662
|
-
yield effects.put({
|
|
663
|
-
type: SET_CURRENT_PAGE,
|
|
664
|
-
formId: formId,
|
|
665
|
-
pageId: formGroups[pageIndex].id,
|
|
666
|
-
pageCount: formGroups.length,
|
|
667
|
-
pageIndex: pageIndex
|
|
668
|
-
});
|
|
669
652
|
}
|
|
670
653
|
function* doFetchForm(action) {
|
|
671
654
|
var _schema$groups;
|
|
@@ -1945,7 +1928,7 @@ const Button = ({
|
|
|
1945
1928
|
useDefaultTheme
|
|
1946
1929
|
}) => {
|
|
1947
1930
|
return /*#__PURE__*/React__default["default"].createElement(ButtonStyled, {
|
|
1948
|
-
className:
|
|
1931
|
+
className: className,
|
|
1949
1932
|
type: type,
|
|
1950
1933
|
onClick: () => action(),
|
|
1951
1934
|
disabled: loading,
|
|
@@ -2012,7 +1995,6 @@ const Form = ({
|
|
|
2012
1995
|
const selectFormFieldErrors = makeSelectFormFieldErrors(formId);
|
|
2013
1996
|
const selectFormEntries = makeSelectFormEntries(formId);
|
|
2014
1997
|
const selectFormPostData = makeSelectFormPostData(formId);
|
|
2015
|
-
const selectFormValidationSent = makeSelectFormValidationSent(formId);
|
|
2016
1998
|
const status = reactRedux.useSelector(selectFormStatus);
|
|
2017
1999
|
const fields = reactRedux.useSelector(selectFormFields);
|
|
2018
2000
|
const pagingInfo = reactRedux.useSelector(selectPagingInfo);
|
|
@@ -2021,7 +2003,6 @@ const Form = ({
|
|
|
2021
2003
|
const errors = reactRedux.useSelector(selectFormFieldErrors);
|
|
2022
2004
|
const entries = reactRedux.useSelector(selectFormEntries);
|
|
2023
2005
|
const formData = reactRedux.useSelector(selectFormPostData);
|
|
2024
|
-
const validate = reactRedux.useSelector(selectFormValidationSent);
|
|
2025
2006
|
if (pagingInfo && pagingInfo.pageCount > 1) {
|
|
2026
2007
|
const isLastPage = pagingInfo.pageCount == pagingInfo.pageIndex + 1;
|
|
2027
2008
|
return /*#__PURE__*/React__default["default"].createElement(ThemeProvider, {
|
|
@@ -2044,19 +2025,22 @@ const Form = ({
|
|
|
2044
2025
|
setDateRangeValues: _setDateRangeValues,
|
|
2045
2026
|
setCheckboxValue: _setCheckboxValue
|
|
2046
2027
|
}), pagingInfo.pageIndex > 0 && /*#__PURE__*/React__default["default"].createElement(Button, {
|
|
2028
|
+
className: "form__btn--prev",
|
|
2047
2029
|
type: "button",
|
|
2048
2030
|
text: "Go Back",
|
|
2049
2031
|
action: () => _doTogglePageBack(formId, pagingInfo.pageIndex - 1),
|
|
2050
2032
|
useDefaultTheme: useDefaultTheme
|
|
2051
2033
|
}), !isLastPage && /*#__PURE__*/React__default["default"].createElement(Button, {
|
|
2034
|
+
className: "form__btn--next",
|
|
2052
2035
|
type: "button",
|
|
2053
2036
|
text: "Next",
|
|
2054
2037
|
action: () => _doTogglePageForward(formId, pagingInfo.pageIndex + 1),
|
|
2055
2038
|
useDefaultTheme: useDefaultTheme
|
|
2056
2039
|
}), isLastPage && /*#__PURE__*/React__default["default"].createElement(Button, {
|
|
2040
|
+
className: "form__btn--submit",
|
|
2057
2041
|
text: (settings === null || settings === void 0 ? void 0 : settings.submitButtonText) || "Submit",
|
|
2058
2042
|
type: "button",
|
|
2059
|
-
loading: status === null || status === void 0 ? void 0 : status.
|
|
2043
|
+
loading: status === null || status === void 0 ? void 0 : status.isSubmitting,
|
|
2060
2044
|
action: () => {
|
|
2061
2045
|
_onSubmit(formId);
|
|
2062
2046
|
if (onCustomSubmit) onCustomSubmit();
|
|
@@ -2069,7 +2053,7 @@ const Form = ({
|
|
|
2069
2053
|
color: "#333"
|
|
2070
2054
|
}), (status === null || status === void 0 ? void 0 : status.hasSuccess) && (status === null || status === void 0 ? void 0 : status.messages.success) && /*#__PURE__*/React__default["default"].createElement("p", {
|
|
2071
2055
|
className: "success-message"
|
|
2072
|
-
}, status.messages.success), (errors === null || errors === void 0 ? void 0 : errors.length) >= 1 &&
|
|
2056
|
+
}, status.messages.success), (errors === null || errors === void 0 ? void 0 : errors.length) >= 1 && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2073
2057
|
className: "form__errors",
|
|
2074
2058
|
role: "alert"
|
|
2075
2059
|
}, errors === null || errors === void 0 ? void 0 : errors.map(({
|
|
@@ -2100,6 +2084,7 @@ const Form = ({
|
|
|
2100
2084
|
entries: entries,
|
|
2101
2085
|
setCheckboxValue: _setCheckboxValue
|
|
2102
2086
|
}), /*#__PURE__*/React__default["default"].createElement(Button, {
|
|
2087
|
+
className: "form__btn--submit",
|
|
2103
2088
|
loading: status === null || status === void 0 ? void 0 : status.isSubmitting,
|
|
2104
2089
|
text: (settings === null || settings === void 0 ? void 0 : settings.submitButtonText) || "Submit",
|
|
2105
2090
|
type: "button",
|
|
@@ -2115,7 +2100,7 @@ const Form = ({
|
|
|
2115
2100
|
color: "#333"
|
|
2116
2101
|
}), (status === null || status === void 0 ? void 0 : status.hasSuccess) && (status === null || status === void 0 ? void 0 : status.messages.success) && /*#__PURE__*/React__default["default"].createElement("p", {
|
|
2117
2102
|
className: "success-message"
|
|
2118
|
-
}, status.messages.success), (errors === null || errors === void 0 ? void 0 : errors.length) >= 1 &&
|
|
2103
|
+
}, status.messages.success), (errors === null || errors === void 0 ? void 0 : errors.length) >= 1 && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2119
2104
|
className: "form__errors",
|
|
2120
2105
|
role: "alert"
|
|
2121
2106
|
}, errors === null || errors === void 0 ? void 0 : errors.map(({
|