@danderson00/react-forms 0.0.18 → 0.0.19
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 +9 -2
- package/dist/input.js +2 -1
- package/dist/submit.js +4 -2
- package/package.json +2 -2
- package/src/Form.js +6 -1
- package/src/input.js +1 -1
- package/src/submit.js +5 -2
package/dist/Form.js
CHANGED
|
@@ -67,6 +67,11 @@ var _default = function _default(ContextProvider) {
|
|
|
67
67
|
error = _useState4[0],
|
|
68
68
|
setError = _useState4[1];
|
|
69
69
|
|
|
70
|
+
var _useState5 = (0, _react.useState)(),
|
|
71
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
72
|
+
valid = _useState6[0],
|
|
73
|
+
setValid = _useState6[1];
|
|
74
|
+
|
|
70
75
|
var form = /*#__PURE__*/(0, _react.createRef)();
|
|
71
76
|
|
|
72
77
|
var getFieldValue = function getFieldValue(path) {
|
|
@@ -84,9 +89,10 @@ var _default = function _default(ContextProvider) {
|
|
|
84
89
|
};
|
|
85
90
|
|
|
86
91
|
var setFieldValue = function setFieldValue(path, value) {
|
|
87
|
-
|
|
92
|
+
setFieldValues(function (previousValues) {
|
|
88
93
|
return (0, _objectPathImmutable.set)(previousValues, path, value);
|
|
89
94
|
});
|
|
95
|
+
setValid(form.current.checkValidity());
|
|
90
96
|
};
|
|
91
97
|
|
|
92
98
|
var onSubmit = function onSubmit(e, additionalValues) {
|
|
@@ -165,7 +171,8 @@ var _default = function _default(ContextProvider) {
|
|
|
165
171
|
setFieldValue: setFieldValue,
|
|
166
172
|
getFieldValue: getFieldValue,
|
|
167
173
|
getFieldValues: getFieldValues,
|
|
168
|
-
onSubmit: onSubmit
|
|
174
|
+
onSubmit: onSubmit,
|
|
175
|
+
valid: valid
|
|
169
176
|
}, mergedAdditionalContext)
|
|
170
177
|
})), error && /*#__PURE__*/(0, _react.createElement)(ErrorMessage, {
|
|
171
178
|
key: 'error',
|
package/dist/input.js
CHANGED
|
@@ -15,7 +15,7 @@ var _inputTypes = _interopRequireDefault(require("./inputTypes"));
|
|
|
15
15
|
|
|
16
16
|
var _throttle2 = _interopRequireDefault(require("./throttle"));
|
|
17
17
|
|
|
18
|
-
var _excluded = ["type", "name", "value", "checked", "defaultValue", "numeric", "onSubmit", "registerFieldValidator", "setFieldValue", "getFieldValue", "getFieldValues", "submitOnChange", "submitOnBlur", "selectOnFocus", "throttle"];
|
|
18
|
+
var _excluded = ["type", "name", "value", "checked", "defaultValue", "numeric", "onSubmit", "registerFieldValidator", "setFieldValue", "getFieldValue", "getFieldValues", "submitOnChange", "submitOnBlur", "selectOnFocus", "throttle", "valid"];
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
21
|
|
|
@@ -226,6 +226,7 @@ var _default = function _default(render) {
|
|
|
226
226
|
submitOnBlur = props.submitOnBlur,
|
|
227
227
|
selectOnFocus = props.selectOnFocus,
|
|
228
228
|
_throttle = props.throttle,
|
|
229
|
+
valid = props.valid,
|
|
229
230
|
passThroughProps = _objectWithoutProperties(props, _excluded);
|
|
230
231
|
|
|
231
232
|
var valueProps = getValueProps({
|
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"];
|
|
12
|
+
var _excluded = ["onSubmit", "registerFieldValidator", "setFieldValue", "getFieldValue", "getFieldValues", "valid", "disableInvalid"];
|
|
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
|
|
|
@@ -62,11 +62,13 @@ var _default = function _default(render) {
|
|
|
62
62
|
setFieldValue = props.setFieldValue,
|
|
63
63
|
getFieldValue = props.getFieldValue,
|
|
64
64
|
getFieldValues = props.getFieldValues,
|
|
65
|
+
valid = props.valid,
|
|
66
|
+
disableInvalid = props.disableInvalid,
|
|
65
67
|
propsToPass = _objectWithoutProperties(props, _excluded);
|
|
66
68
|
|
|
67
69
|
var finalProps = _objectSpread(_objectSpread({}, propsToPass), {}, {
|
|
68
70
|
onClick: onClick,
|
|
69
|
-
disabled: executing
|
|
71
|
+
disabled: executing || props.disableInvalid && !props.valid
|
|
70
72
|
});
|
|
71
73
|
|
|
72
74
|
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.19",
|
|
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",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"component"
|
|
50
50
|
],
|
|
51
51
|
"author": "danderson00",
|
|
52
|
-
"license": "
|
|
52
|
+
"license": "MIT",
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
package/src/Form.js
CHANGED
|
@@ -6,6 +6,7 @@ export default (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
|
6
6
|
const [fieldValues, setFieldValues] = useState(props.values || {})
|
|
7
7
|
const [fieldValidators, registerFieldValidator] = useReducer((validators, validator) => [...validators, validator], [])
|
|
8
8
|
const [error, setError] = useState()
|
|
9
|
+
const [valid, setValid] = useState()
|
|
9
10
|
const form = createRef()
|
|
10
11
|
|
|
11
12
|
const getFieldValue = path => get(fieldValues, path)
|
|
@@ -15,7 +16,10 @@ export default (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
|
15
16
|
{}
|
|
16
17
|
)
|
|
17
18
|
|
|
18
|
-
const setFieldValue = (path, value) =>
|
|
19
|
+
const setFieldValue = (path, value) => {
|
|
20
|
+
setFieldValues(previousValues => set(previousValues, path, value))
|
|
21
|
+
setValid(form.current.checkValidity())
|
|
22
|
+
}
|
|
19
23
|
|
|
20
24
|
const onSubmit = (e, additionalValues) => {
|
|
21
25
|
fieldValidators.forEach(setFieldValidated => setFieldValidated())
|
|
@@ -88,6 +92,7 @@ export default (ContextProvider, additionalContext = {}, ErrorMessage) => (
|
|
|
88
92
|
getFieldValue,
|
|
89
93
|
getFieldValues,
|
|
90
94
|
onSubmit,
|
|
95
|
+
valid,
|
|
91
96
|
...mergedAdditionalContext
|
|
92
97
|
}
|
|
93
98
|
}),
|
package/src/input.js
CHANGED
|
@@ -124,7 +124,7 @@ export default (render, options = {}) => function Input(props) {
|
|
|
124
124
|
const {
|
|
125
125
|
type, name, value, checked, defaultValue, numeric,
|
|
126
126
|
onSubmit, registerFieldValidator, setFieldValue, getFieldValue, getFieldValues,
|
|
127
|
-
submitOnChange, submitOnBlur, selectOnFocus, throttle,
|
|
127
|
+
submitOnChange, submitOnBlur, selectOnFocus, throttle, valid,
|
|
128
128
|
...passThroughProps
|
|
129
129
|
} = props
|
|
130
130
|
const valueProps = getValueProps({ currentValue: getFieldValue(name) })
|
package/src/submit.js
CHANGED
|
@@ -14,12 +14,15 @@ export default render => function Submit(props) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
onSubmit, registerFieldValidator, setFieldValue, getFieldValue, getFieldValues,
|
|
19
|
+
valid, disableInvalid, ...propsToPass
|
|
20
|
+
} = props
|
|
18
21
|
|
|
19
22
|
const finalProps = {
|
|
20
23
|
...propsToPass,
|
|
21
24
|
onClick,
|
|
22
|
-
disabled: executing
|
|
25
|
+
disabled: executing || (props.disableInvalid && !props.valid)
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
return render(finalProps)
|