@zengenti/contensis-react-base 3.0.2-beta.15 → 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 +58 -73
- package/cjs/forms.js.map +1 -1
- package/esm/forms.js +59 -74
- package/esm/forms.js.map +1 -1
- package/package.json +1 -1
package/cjs/forms.js
CHANGED
|
@@ -319,7 +319,7 @@ const makeSelectFormValidationSent = formId => reselect.createSelector(selectFor
|
|
|
319
319
|
var _forms$formId16;
|
|
320
320
|
return forms === null || forms === void 0 ? void 0 : (_forms$formId16 = forms[formId]) === null || _forms$formId16 === void 0 ? void 0 : _forms$formId16.status.validation.sent;
|
|
321
321
|
});
|
|
322
|
-
const makeSelectFormGroup
|
|
322
|
+
const makeSelectFormGroup = formId => reselect.createSelector(selectForms, forms => {
|
|
323
323
|
var _forms$formId17;
|
|
324
324
|
return forms === null || forms === void 0 ? void 0 : (_forms$formId17 = forms[formId]) === null || _forms$formId17 === void 0 ? void 0 : _forms$formId17.groups;
|
|
325
325
|
});
|
|
@@ -339,7 +339,7 @@ const selectors = {
|
|
|
339
339
|
makeSelectDefaultLang,
|
|
340
340
|
makeSelectFormSuccessMessage,
|
|
341
341
|
makeSelectFormValidationSent,
|
|
342
|
-
makeSelectFormGroup
|
|
342
|
+
makeSelectFormGroup,
|
|
343
343
|
makeSelectHasError
|
|
344
344
|
};
|
|
345
345
|
|
|
@@ -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;
|
|
@@ -917,7 +900,7 @@ const FormStyled = styled__default["default"].form.withConfig({
|
|
|
917
900
|
theme,
|
|
918
901
|
useDefaultTheme
|
|
919
902
|
}) => {
|
|
920
|
-
return styled.css(["", ""], useDefaultTheme && styled.css(["> div:not(:first-child){margin-top:16px;}padding:0 16px;.success-message{font-size:18px;margin:0;}.visuallyHidden{position:absolute;left:-10000px;top:auto;width:1px;height:1px;overflow:hidden;}.loading{display:block;margin:24px auto;}label{display:inline-block;.isRequired{color:", ";}}input,textarea,select{display:block;font-family:inherit;background-color:", ";border-radius:3px;border:1px solid ", ";height:40px;padding:8px;margin-top:4px;width:100%;}input:-webkit-autofill,input:-webkit-autofill:hover,input:-webkit-autofill:focus,input:-webkit-autofill:active{-webkit-box-shadow:0 0 0 30px ", " inset;}textarea{height:200px;resize:none;}[aria-invalid='false']{background:", ";border:1px solid ", ";&:-webkit-autofill,&:-webkit-autofill:hover,&:-webkit-autofill:focus,&:-webkit-autofill:active{-webkit-box-shadow:0 0 0 30px", " inset;}}[aria-invalid='true']{background:", ";border:1px solid ", ";&:-webkit-autofill,&:-webkit-autofill:hover,&:-webkit-autofill:focus,&:-webkit-autofill:active{-webkit-box-shadow:0 0 0 30px", " inset;}}input ~ .svg{position:absolute;right:8px;top:50%;transform:translateY(-50%);}textarea ~ .svg{position:absolute;right:8px;top:8px;}"], theme.colors.red_darker, theme.colors.white, theme.colors.light_grey_darkest, theme.colors.white, theme.colors.green_lightest, theme.colors.green_darker, theme.colors.green_lightest, theme.colors.red_lightest, theme.colors.red_darker, theme.colors.red_lightest));
|
|
903
|
+
return styled.css(["", ""], useDefaultTheme && styled.css(["> div:not(:first-child){margin-top:16px;}padding:0 16px;.success-message{font-size:18px;margin:0;}.visuallyHidden{position:absolute;left:-10000px;top:auto;width:1px;height:1px;overflow:hidden;}.loading{display:block;margin:24px auto;}label{display:inline-block;.isRequired{color:", ";}}input,textarea,select{display:block;font-family:inherit;background-color:", ";border-radius:3px;border:1px solid ", ";height:40px;padding:8px;margin-top:4px;width:100%;}input:-webkit-autofill,input:-webkit-autofill:hover,input:-webkit-autofill:focus,input:-webkit-autofill:active{-webkit-box-shadow:0 0 0 30px ", " inset;}textarea{height:200px;resize:none;}[aria-invalid='false']{background:", ";border:1px solid ", ";&:-webkit-autofill,&:-webkit-autofill:hover,&:-webkit-autofill:focus,&:-webkit-autofill:active{-webkit-box-shadow:0 0 0 30px", " inset;}}[aria-invalid='true']{background:", ";border:1px solid ", ";&:-webkit-autofill,&:-webkit-autofill:hover,&:-webkit-autofill:focus,&:-webkit-autofill:active{-webkit-box-shadow:0 0 0 30px", " inset;}}input ~ .svg{position:absolute;right:8px;top:50%;transform:translateY(-50%);}textarea ~ .svg{position:absolute;right:8px;top:8px;}button:not(:last-of-type){margin-right:16px;}"], theme.colors.red_darker, theme.colors.white, theme.colors.light_grey_darkest, theme.colors.white, theme.colors.green_lightest, theme.colors.green_darker, theme.colors.green_lightest, theme.colors.red_lightest, theme.colors.red_darker, theme.colors.red_lightest));
|
|
921
904
|
});
|
|
922
905
|
|
|
923
906
|
const Label = ({
|
|
@@ -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, {
|
|
@@ -2030,12 +2011,7 @@ const Form = ({
|
|
|
2030
2011
|
className: className,
|
|
2031
2012
|
id: formId,
|
|
2032
2013
|
useDefaultTheme: useDefaultTheme
|
|
2033
|
-
}, !(status !== null && status !== void 0 && status.hasSuccess) && !(status !== null && status !== void 0 && status.isLoading) && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
2034
|
-
type: "button",
|
|
2035
|
-
text: "Go Back",
|
|
2036
|
-
action: () => _doTogglePageBack(formId, pagingInfo.pageIndex - 1),
|
|
2037
|
-
useDefaultTheme: useDefaultTheme
|
|
2038
|
-
}), /*#__PURE__*/React__default["default"].createElement(FormComposer, {
|
|
2014
|
+
}, !(status !== null && status !== void 0 && status.hasSuccess) && !(status !== null && status !== void 0 && status.isLoading) && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(FormComposer, {
|
|
2039
2015
|
fields: fields,
|
|
2040
2016
|
formData: formData,
|
|
2041
2017
|
formId: formId,
|
|
@@ -2048,15 +2024,23 @@ const Form = ({
|
|
|
2048
2024
|
entries: entries,
|
|
2049
2025
|
setDateRangeValues: _setDateRangeValues,
|
|
2050
2026
|
setCheckboxValue: _setCheckboxValue
|
|
2027
|
+
}), pagingInfo.pageIndex > 0 && /*#__PURE__*/React__default["default"].createElement(Button, {
|
|
2028
|
+
className: "form__btn--prev",
|
|
2029
|
+
type: "button",
|
|
2030
|
+
text: "Go Back",
|
|
2031
|
+
action: () => _doTogglePageBack(formId, pagingInfo.pageIndex - 1),
|
|
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(({
|