@tsed/react-formio 1.12.0 → 1.13.0
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/dist/components/form/form.component.d.ts +2 -0
- package/dist/components/form/form.stories.d.ts +37 -0
- package/dist/components/form/useForm.hook.d.ts +1 -0
- package/dist/index.js +51 -4
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +25 -2
- package/dist/index.modern.js.map +1 -1
- package/package.json +4 -4
- package/readme.md +51 -18
- package/src/components/form/form.component.tsx +3 -1
- package/src/components/form/form.stories.tsx +66 -2
- package/src/components/form/useForm.hook.ts +25 -1
package/dist/index.modern.js
CHANGED
|
@@ -1928,12 +1928,29 @@ function useForm(props) {
|
|
|
1928
1928
|
const instance = useRef();
|
|
1929
1929
|
const events = useRef(new Map());
|
|
1930
1930
|
|
|
1931
|
+
async function customValidation(submission, callback) {
|
|
1932
|
+
if (events.current.has("onAsyncSubmit")) {
|
|
1933
|
+
try {
|
|
1934
|
+
await events.current.get("onAsyncSubmit")(submission);
|
|
1935
|
+
} catch (err) {
|
|
1936
|
+
callback((err == null ? void 0 : err.errors) || err);
|
|
1937
|
+
}
|
|
1938
|
+
} else {
|
|
1939
|
+
callback(null);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1931
1943
|
const createWebForm = (srcOrForm, options) => {
|
|
1932
1944
|
options = Object.assign({}, options);
|
|
1933
1945
|
srcOrForm = typeof srcOrForm === "string" ? srcOrForm : cloneDeep(srcOrForm);
|
|
1934
1946
|
|
|
1935
1947
|
if (!instance.current) {
|
|
1948
|
+
var _options, _options$hooks;
|
|
1949
|
+
|
|
1936
1950
|
isLoaded.current = false;
|
|
1951
|
+
options.hooks = _extends({}, options.hooks || {}, {
|
|
1952
|
+
customValidation: ((_options = options) == null ? void 0 : (_options$hooks = _options.hooks) == null ? void 0 : _options$hooks.customValidation) || customValidation
|
|
1953
|
+
});
|
|
1937
1954
|
instance.current = new Form$1(element.current, srcOrForm, options);
|
|
1938
1955
|
instance.current.onAny((event, ...args) => {
|
|
1939
1956
|
if (!instance.current) {
|
|
@@ -1956,7 +1973,8 @@ function useForm(props) {
|
|
|
1956
1973
|
events.current.set(funcName, fn);
|
|
1957
1974
|
}
|
|
1958
1975
|
|
|
1959
|
-
|
|
1976
|
+
instance.current.instance.setAlert("success", "");
|
|
1977
|
+
events.current.get(funcName)(...args, instance.current);
|
|
1960
1978
|
}
|
|
1961
1979
|
}
|
|
1962
1980
|
});
|
|
@@ -2015,6 +2033,9 @@ function useForm(props) {
|
|
|
2015
2033
|
useEffect(() => {
|
|
2016
2034
|
props.onSubmit && events.current.set("onSubmit", props.onSubmit);
|
|
2017
2035
|
}, [props.onSubmit, events]);
|
|
2036
|
+
useEffect(() => {
|
|
2037
|
+
props.onAsyncSubmit && events.current.set("onAsyncSubmit", props.onAsyncSubmit);
|
|
2038
|
+
}, [props.onAsyncSubmit, events]);
|
|
2018
2039
|
useEffect(() => {
|
|
2019
2040
|
props.onSubmitDone && events.current.set("onSubmitDone", props.onSubmitDone);
|
|
2020
2041
|
}, [props.onSubmitDone, events]);
|
|
@@ -2066,7 +2087,8 @@ Form.propTypes = {
|
|
|
2066
2087
|
noAlerts: PropTypes.bool,
|
|
2067
2088
|
i18n: PropTypes.any,
|
|
2068
2089
|
template: PropTypes.string,
|
|
2069
|
-
saveDraft: PropTypes.bool
|
|
2090
|
+
saveDraft: PropTypes.bool,
|
|
2091
|
+
hooks: PropTypes.any
|
|
2070
2092
|
}),
|
|
2071
2093
|
onPrevPage: PropTypes.func,
|
|
2072
2094
|
onNextPage: PropTypes.func,
|
|
@@ -2075,6 +2097,7 @@ Form.propTypes = {
|
|
|
2075
2097
|
onCustomEvent: PropTypes.func,
|
|
2076
2098
|
onComponentChange: PropTypes.func,
|
|
2077
2099
|
onSubmit: PropTypes.func,
|
|
2100
|
+
onAsyncSubmit: PropTypes.func,
|
|
2078
2101
|
onSubmitDone: PropTypes.func,
|
|
2079
2102
|
onFormLoad: PropTypes.func,
|
|
2080
2103
|
onError: PropTypes.func,
|