@maif/react-forms 1.0.6 → 1.0.7
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/react-form.js +1 -1
- package/lib/form.d.ts +2 -11
- package/lib/form.js +26 -12
- package/package.json +1 -1
package/lib/form.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
flow: any;
|
|
4
|
-
value: any;
|
|
5
|
-
inputWrapper: any;
|
|
6
|
-
onSubmit: any;
|
|
7
|
-
footer: any;
|
|
8
|
-
style?: {} | undefined;
|
|
9
|
-
className: any;
|
|
10
|
-
options?: {} | undefined;
|
|
11
|
-
}): JSX.Element;
|
|
1
|
+
export const Form: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
|
2
|
+
import React from "react";
|
package/lib/form.js
CHANGED
|
@@ -166,12 +166,14 @@ var getDefaultValues = function getDefaultValues(flow, schema) {
|
|
|
166
166
|
}, {});
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
-
var Form = function
|
|
169
|
+
var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
|
|
170
170
|
var schema = _ref2.schema,
|
|
171
171
|
flow = _ref2.flow,
|
|
172
172
|
value = _ref2.value,
|
|
173
173
|
inputWrapper = _ref2.inputWrapper,
|
|
174
174
|
onSubmit = _ref2.onSubmit,
|
|
175
|
+
_ref2$onError = _ref2.onError,
|
|
176
|
+
onError = _ref2$onError === void 0 ? function () {} : _ref2$onError,
|
|
175
177
|
footer = _ref2.footer,
|
|
176
178
|
_ref2$style = _ref2.style,
|
|
177
179
|
style = _ref2$style === void 0 ? {} : _ref2$style,
|
|
@@ -277,7 +279,7 @@ var Form = function Form(_ref2) {
|
|
|
277
279
|
defaultValues: cleanInputArray(value || defaultValues)
|
|
278
280
|
});
|
|
279
281
|
var register = methods.register,
|
|
280
|
-
|
|
282
|
+
_handleSubmit = methods.handleSubmit,
|
|
281
283
|
errors = methods.formState.errors,
|
|
282
284
|
control = methods.control,
|
|
283
285
|
_reset = methods.reset,
|
|
@@ -294,12 +296,14 @@ var Form = function Form(_ref2) {
|
|
|
294
296
|
_reset(cleanInputArray(value || defaultValues));
|
|
295
297
|
}, [schema]);
|
|
296
298
|
var data = watch();
|
|
299
|
+
var prevData = usePrevious(data);
|
|
297
300
|
(0, _react.useEffect)(function () {
|
|
298
301
|
//todo: with debounce
|
|
299
|
-
if (!!options.autosubmit) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
302
|
+
if (!!options.autosubmit && JSON.stringify(data) !== JSON.stringify(prevData)) {
|
|
303
|
+
_handleSubmit(function (data) {
|
|
304
|
+
var clean = cleanOutputArray(data);
|
|
305
|
+
onSubmit(clean);
|
|
306
|
+
}, onError)();
|
|
303
307
|
}
|
|
304
308
|
}, [data]);
|
|
305
309
|
|
|
@@ -307,12 +311,22 @@ var Form = function Form(_ref2) {
|
|
|
307
311
|
console.log(watch());
|
|
308
312
|
}
|
|
309
313
|
|
|
314
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
|
315
|
+
return {
|
|
316
|
+
handleSubmit: function handleSubmit() {
|
|
317
|
+
return _handleSubmit(function (data) {
|
|
318
|
+
var clean = cleanOutputArray(data);
|
|
319
|
+
onSubmit(clean);
|
|
320
|
+
}, onError)();
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
});
|
|
310
324
|
return /*#__PURE__*/_react["default"].createElement(_reactHookForm.FormProvider, methods, /*#__PURE__*/_react["default"].createElement("form", {
|
|
311
325
|
className: className || classes.pr_15,
|
|
312
|
-
onSubmit:
|
|
326
|
+
onSubmit: _handleSubmit(function (data) {
|
|
313
327
|
var clean = cleanOutputArray(data);
|
|
314
|
-
|
|
315
|
-
})
|
|
328
|
+
onSubmit(clean);
|
|
329
|
+
}, onError)
|
|
316
330
|
}, formFlow.map(function (entry, idx) {
|
|
317
331
|
if (entry && _typeof(entry) === 'object') {
|
|
318
332
|
var errored = entry.flow.some(function (step) {
|
|
@@ -379,12 +393,12 @@ var Form = function Form(_ref2) {
|
|
|
379
393
|
reset: function reset() {
|
|
380
394
|
return _reset(defaultValues);
|
|
381
395
|
},
|
|
382
|
-
valid:
|
|
396
|
+
valid: _handleSubmit(function (data) {
|
|
383
397
|
return onSubmit(cleanOutputArray(data));
|
|
384
|
-
}),
|
|
398
|
+
}, onError),
|
|
385
399
|
actions: options.actions
|
|
386
400
|
})));
|
|
387
|
-
};
|
|
401
|
+
});
|
|
388
402
|
|
|
389
403
|
exports.Form = Form;
|
|
390
404
|
|