@danderson00/react-forms 0.0.30 → 0.0.31

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 CHANGED
@@ -100,12 +100,14 @@ var Form = function Form(ContextProvider) {
100
100
  setValid(form.current.checkValidity());
101
101
  };
102
102
 
103
- var onSubmit = function onSubmit(e, additionalValues, additionalArg) {
103
+ var onSubmit = function onSubmit(e, additionalValues) {
104
+ var submitOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
105
+ var validate = submitOptions.validate;
104
106
  fieldValidators.forEach(function (setFieldValidated) {
105
107
  return setFieldValidated();
106
108
  });
107
109
 
108
- if (form.current.checkValidity() && props.onSubmit) {
110
+ if ((validate === false || form.current.checkValidity()) && props.onSubmit) {
109
111
  setError(undefined);
110
112
  var interactiveElements = form.current.querySelectorAll('input,button,textarea,select');
111
113
 
@@ -132,8 +134,7 @@ var Form = function Form(ContextProvider) {
132
134
  return result;
133
135
  };
134
136
 
135
- var args = [mapFieldValues(_objectSpread(_objectSpread({}, fieldValues), additionalValues))].concat(_toConsumableArray(additionalArg ? [additionalArg] : []));
136
- var result = props.onSubmit.apply(props, _toConsumableArray(args));
137
+ var result = props.onSubmit(mapFieldValues(_objectSpread(_objectSpread({}, fieldValues), additionalValues)));
137
138
 
138
139
  if (result && typeof result.then === 'function') {
139
140
  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", "values"];
12
+ var _excluded = ["onSubmit", "registerFieldValidator", "setFieldValue", "getFieldValue", "getFieldValues", "valid", "validate", "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
 
@@ -47,6 +47,7 @@ var _default = function _default(render) {
47
47
  getFieldValue = props.getFieldValue,
48
48
  getFieldValues = props.getFieldValues,
49
49
  valid = props.valid,
50
+ validate = props.validate,
50
51
  disableInvalid = props.disableInvalid,
51
52
  values = props.values,
52
53
  propsToPass = _objectWithoutProperties(props, _excluded); // TODO: set executing when form is triggered by enter key
@@ -58,7 +59,9 @@ var _default = function _default(render) {
58
59
  setExecuting = _useState2[1];
59
60
 
60
61
  var onClick = function onClick(e) {
61
- var result = onSubmit(e, values);
62
+ var result = onSubmit(e, values, {
63
+ validate: validate
64
+ });
62
65
 
63
66
  if (result && result["finally"] && typeof result["finally"] === 'function') {
64
67
  setExecuting(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danderson00/react-forms",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
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",
package/src/Form.js CHANGED
@@ -27,10 +27,12 @@ const Form = (ContextProvider, additionalContext = {}, ErrorMessage) => (
27
27
  setValid(form.current.checkValidity())
28
28
  }
29
29
 
30
- const onSubmit = (e, additionalValues, additionalArg) => {
30
+ const onSubmit = (e, additionalValues, submitOptions = {}) => {
31
+ const { validate } = submitOptions
32
+
31
33
  fieldValidators.forEach(setFieldValidated => setFieldValidated())
32
34
 
33
- if(form.current.checkValidity() && props.onSubmit) {
35
+ if((validate === false || form.current.checkValidity()) && props.onSubmit) {
34
36
  setError(undefined)
35
37
 
36
38
  const interactiveElements = form.current.querySelectorAll('input,button,textarea,select')
@@ -52,11 +54,7 @@ const Form = (ContextProvider, additionalContext = {}, ErrorMessage) => (
52
54
  return result
53
55
  }
54
56
 
55
- const args = [
56
- mapFieldValues({ ...fieldValues, ...additionalValues }),
57
- ...(additionalArg ? [additionalArg] : [])
58
- ]
59
- const result = props.onSubmit(...args)
57
+ const result = props.onSubmit(mapFieldValues({ ...fieldValues, ...additionalValues }))
60
58
  if(result && typeof result.then === 'function') {
61
59
  setFormDisabled(true)
62
60
  result
package/src/submit.js CHANGED
@@ -5,14 +5,14 @@ export default render => function Submit(props) {
5
5
 
6
6
  const {
7
7
  onSubmit, registerFieldValidator, setFieldValue, getFieldValue, getFieldValues,
8
- valid, disableInvalid, values, ...propsToPass
8
+ valid, validate, disableInvalid, values, ...propsToPass
9
9
  } = props
10
10
 
11
11
  // TODO: set executing when form is triggered by enter key
12
12
  const [executing, setExecuting] = useState(false)
13
13
 
14
14
  const onClick = e => {
15
- const result = onSubmit(e, values)
15
+ const result = onSubmit(e, values, { validate })
16
16
  if(result && result.finally && typeof result.finally === 'function') {
17
17
  setExecuting(true)
18
18
  result.finally(() => setExecuting(false))