@danderson00/react-forms 0.0.29 → 0.0.30
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/Form.js +3 -2
- package/dist/submit.js +19 -17
- package/package.json +3 -3
- package/src/Form.js +6 -2
- package/src/submit.js +7 -7
package/dist/Form.js
CHANGED
|
@@ -100,7 +100,7 @@ var Form = function Form(ContextProvider) {
|
|
|
100
100
|
setValid(form.current.checkValidity());
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
var onSubmit = function onSubmit(e, additionalValues) {
|
|
103
|
+
var onSubmit = function onSubmit(e, additionalValues, additionalArg) {
|
|
104
104
|
fieldValidators.forEach(function (setFieldValidated) {
|
|
105
105
|
return setFieldValidated();
|
|
106
106
|
});
|
|
@@ -132,7 +132,8 @@ var Form = function Form(ContextProvider) {
|
|
|
132
132
|
return result;
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
var
|
|
135
|
+
var args = [mapFieldValues(_objectSpread(_objectSpread({}, fieldValues), additionalValues))].concat(_toConsumableArray(additionalArg ? [additionalArg] : []));
|
|
136
|
+
var result = props.onSubmit.apply(props, _toConsumableArray(args));
|
|
136
137
|
|
|
137
138
|
if (result && typeof result.then === 'function') {
|
|
138
139
|
setFormDisabled(true);
|
package/dist/submit.js
CHANGED
|
@@ -9,7 +9,7 @@ exports["default"] = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
12
|
-
var _excluded = ["onSubmit", "registerFieldValidator", "setFieldValue", "getFieldValue", "getFieldValues", "valid", "disableInvalid"];
|
|
12
|
+
var _excluded = ["onSubmit", "registerFieldValidator", "setFieldValue", "getFieldValue", "getFieldValues", "valid", "disableInvalid", "values"];
|
|
13
13
|
|
|
14
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
15
|
|
|
@@ -21,10 +21,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
21
21
|
|
|
22
22
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
23
|
|
|
24
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
25
|
-
|
|
26
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
27
|
-
|
|
28
24
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
29
25
|
|
|
30
26
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -37,9 +33,24 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
37
33
|
|
|
38
34
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
39
35
|
|
|
36
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
37
|
+
|
|
38
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
39
|
+
|
|
40
40
|
var _default = function _default(render) {
|
|
41
41
|
return function Submit(props) {
|
|
42
|
-
if (!props.onSubmit) throw new Error('Button components must be contained within a Form component');
|
|
42
|
+
if (!props.onSubmit) throw new Error('Button components must be contained within a Form component');
|
|
43
|
+
|
|
44
|
+
var onSubmit = props.onSubmit,
|
|
45
|
+
registerFieldValidator = props.registerFieldValidator,
|
|
46
|
+
setFieldValue = props.setFieldValue,
|
|
47
|
+
getFieldValue = props.getFieldValue,
|
|
48
|
+
getFieldValues = props.getFieldValues,
|
|
49
|
+
valid = props.valid,
|
|
50
|
+
disableInvalid = props.disableInvalid,
|
|
51
|
+
values = props.values,
|
|
52
|
+
propsToPass = _objectWithoutProperties(props, _excluded); // TODO: set executing when form is triggered by enter key
|
|
53
|
+
|
|
43
54
|
|
|
44
55
|
var _useState = (0, _react.useState)(false),
|
|
45
56
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -47,7 +58,7 @@ var _default = function _default(render) {
|
|
|
47
58
|
setExecuting = _useState2[1];
|
|
48
59
|
|
|
49
60
|
var onClick = function onClick(e) {
|
|
50
|
-
var result =
|
|
61
|
+
var result = onSubmit(e, values);
|
|
51
62
|
|
|
52
63
|
if (result && result["finally"] && typeof result["finally"] === 'function') {
|
|
53
64
|
setExecuting(true);
|
|
@@ -57,18 +68,9 @@ var _default = function _default(render) {
|
|
|
57
68
|
}
|
|
58
69
|
};
|
|
59
70
|
|
|
60
|
-
var onSubmit = props.onSubmit,
|
|
61
|
-
registerFieldValidator = props.registerFieldValidator,
|
|
62
|
-
setFieldValue = props.setFieldValue,
|
|
63
|
-
getFieldValue = props.getFieldValue,
|
|
64
|
-
getFieldValues = props.getFieldValues,
|
|
65
|
-
valid = props.valid,
|
|
66
|
-
disableInvalid = props.disableInvalid,
|
|
67
|
-
propsToPass = _objectWithoutProperties(props, _excluded);
|
|
68
|
-
|
|
69
71
|
var finalProps = _objectSpread(_objectSpread({}, propsToPass), {}, {
|
|
70
72
|
onClick: onClick,
|
|
71
|
-
disabled: props.disabled || executing ||
|
|
73
|
+
disabled: props.disabled || executing || disableInvalid && !valid
|
|
72
74
|
});
|
|
73
75
|
|
|
74
76
|
return render(finalProps);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danderson00/react-forms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"description": "Ultra simple, stateless, validated forms for use in React function components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"@babel/preset-env": "^7.4.4",
|
|
22
22
|
"@babel/preset-react": "^7.0.0",
|
|
23
23
|
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.1",
|
|
24
|
-
"babel-jest": "26.6.
|
|
24
|
+
"babel-jest": "26.6.3",
|
|
25
25
|
"enzyme": "^3.9.0",
|
|
26
|
-
"jest": "26.6.
|
|
26
|
+
"jest": "26.6.3",
|
|
27
27
|
"react": "^17.0.2",
|
|
28
28
|
"react-dom": "^17.0.2"
|
|
29
29
|
},
|
package/src/Form.js
CHANGED
|
@@ -27,7 +27,7 @@ const Form = (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
|
27
27
|
setValid(form.current.checkValidity())
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const onSubmit = (e, additionalValues) => {
|
|
30
|
+
const onSubmit = (e, additionalValues, additionalArg) => {
|
|
31
31
|
fieldValidators.forEach(setFieldValidated => setFieldValidated())
|
|
32
32
|
|
|
33
33
|
if(form.current.checkValidity() && props.onSubmit) {
|
|
@@ -52,7 +52,11 @@ const Form = (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
|
52
52
|
return result
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const
|
|
55
|
+
const args = [
|
|
56
|
+
mapFieldValues({ ...fieldValues, ...additionalValues }),
|
|
57
|
+
...(additionalArg ? [additionalArg] : [])
|
|
58
|
+
]
|
|
59
|
+
const result = props.onSubmit(...args)
|
|
56
60
|
if(result && typeof result.then === 'function') {
|
|
57
61
|
setFormDisabled(true)
|
|
58
62
|
result
|
package/src/submit.js
CHANGED
|
@@ -3,26 +3,26 @@ import React, { useState } from 'react'
|
|
|
3
3
|
export default render => function Submit(props) {
|
|
4
4
|
if(!props.onSubmit) throw new Error('Button components must be contained within a Form component')
|
|
5
5
|
|
|
6
|
+
const {
|
|
7
|
+
onSubmit, registerFieldValidator, setFieldValue, getFieldValue, getFieldValues,
|
|
8
|
+
valid, disableInvalid, values, ...propsToPass
|
|
9
|
+
} = props
|
|
10
|
+
|
|
6
11
|
// TODO: set executing when form is triggered by enter key
|
|
7
12
|
const [executing, setExecuting] = useState(false)
|
|
8
13
|
|
|
9
14
|
const onClick = e => {
|
|
10
|
-
const result =
|
|
15
|
+
const result = onSubmit(e, values)
|
|
11
16
|
if(result && result.finally && typeof result.finally === 'function') {
|
|
12
17
|
setExecuting(true)
|
|
13
18
|
result.finally(() => setExecuting(false))
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
const {
|
|
18
|
-
onSubmit, registerFieldValidator, setFieldValue, getFieldValue, getFieldValues,
|
|
19
|
-
valid, disableInvalid, ...propsToPass
|
|
20
|
-
} = props
|
|
21
|
-
|
|
22
22
|
const finalProps = {
|
|
23
23
|
...propsToPass,
|
|
24
24
|
onClick,
|
|
25
|
-
disabled: props.disabled || executing || (
|
|
25
|
+
disabled: props.disabled || executing || (disableInvalid && !valid)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
return render(finalProps)
|