@kaspernj/api-maker 1.0.406 → 1.0.408
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/package.json +1 -1
- package/src/form.jsx +12 -4
package/package.json
CHANGED
package/src/form.jsx
CHANGED
|
@@ -2,14 +2,15 @@ import {createContext, memo, useContext, useMemo} from "react"
|
|
|
2
2
|
import BaseComponent from "./base-component"
|
|
3
3
|
import FormDataObjectizer from "form-data-objectizer"
|
|
4
4
|
import {Platform} from "react-native"
|
|
5
|
+
import PropTypes from "prop-types"
|
|
5
6
|
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
6
7
|
|
|
7
8
|
const FormContext = createContext(null)
|
|
8
9
|
|
|
9
10
|
class FormInputs {
|
|
10
|
-
constructor(
|
|
11
|
+
constructor(props) {
|
|
11
12
|
this.inputs = {}
|
|
12
|
-
this.onSubmit = onSubmit
|
|
13
|
+
this.onSubmit = props?.onSubmit
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
asObject() {
|
|
@@ -47,8 +48,15 @@ class FormInputs {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
const Form = memo(shapeComponent(class Form extends BaseComponent {
|
|
51
|
+
static propTypes = {
|
|
52
|
+
children: PropTypes.node,
|
|
53
|
+
formRef: PropTypes.object,
|
|
54
|
+
onSubmit: PropTypes.func,
|
|
55
|
+
setForm: PropTypes.func
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
render() {
|
|
51
|
-
const {children, onSubmit, setForm, ...restProps} = this.props
|
|
59
|
+
const {children, formRef, onSubmit, setForm, ...restProps} = this.props
|
|
52
60
|
const form = useMemo(() => new FormInputs({onSubmit}), [])
|
|
53
61
|
|
|
54
62
|
useMemo(() => {
|
|
@@ -60,7 +68,7 @@ const Form = memo(shapeComponent(class Form extends BaseComponent {
|
|
|
60
68
|
return (
|
|
61
69
|
<FormContext.Provider value={form}>
|
|
62
70
|
{Platform.OS == "web" &&
|
|
63
|
-
<form onSubmit={this.tt.onFormSubmit} {...restProps}>
|
|
71
|
+
<form ref={formRef} onSubmit={this.tt.onFormSubmit} {...restProps}>
|
|
64
72
|
{children}
|
|
65
73
|
</form>
|
|
66
74
|
}
|