@kaspernj/api-maker 1.0.342 → 1.0.343
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
CHANGED
package/src/base-model.mjs
CHANGED
|
@@ -460,7 +460,7 @@ export default class BaseModel {
|
|
|
460
460
|
BaseModel.sendValidationErrorsEvent(validationErrors, options)
|
|
461
461
|
|
|
462
462
|
if (!options || options.throwValidationError != false) {
|
|
463
|
-
throw
|
|
463
|
+
throw error
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
|
package/src/use-input.mjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {dig, digg
|
|
1
|
+
import {dig, digg} from "diggerize"
|
|
2
2
|
import {useCallback, useEffect, useMemo} from "react"
|
|
3
3
|
import idForComponent from "./inputs/id-for-component.mjs"
|
|
4
4
|
import nameForComponent from "./inputs/name-for-component.mjs"
|
|
5
5
|
import strftime from "strftime"
|
|
6
|
-
import useEventListener from "./use-event-listener.mjs"
|
|
7
6
|
import useShape from "set-state-compare/src/use-shape.js"
|
|
7
|
+
import useValidationErrors from "./use-validation-errors.mjs"
|
|
8
8
|
|
|
9
9
|
const useInput = ({props, wrapperOptions}) => {
|
|
10
10
|
const s = useShape(props)
|
|
11
11
|
|
|
12
12
|
s.useStates({
|
|
13
|
-
errors: [],
|
|
14
13
|
form: undefined
|
|
15
14
|
})
|
|
16
15
|
|
|
@@ -73,12 +72,6 @@ const useInput = ({props, wrapperOptions}) => {
|
|
|
73
72
|
}
|
|
74
73
|
}, [])
|
|
75
74
|
|
|
76
|
-
const inputName = useCallback(() => {
|
|
77
|
-
if (s.state.blankInputName) return ""
|
|
78
|
-
|
|
79
|
-
return getName()
|
|
80
|
-
}, [])
|
|
81
|
-
|
|
82
75
|
const inputRefBackup = useCallback(() => {
|
|
83
76
|
if (!s.meta._inputRefBackup) s.meta._inputRefBackup = React.createRef()
|
|
84
77
|
|
|
@@ -105,16 +98,6 @@ const useInput = ({props, wrapperOptions}) => {
|
|
|
105
98
|
}
|
|
106
99
|
}, [])
|
|
107
100
|
|
|
108
|
-
const onValidationErrors = useCallback((event) => {
|
|
109
|
-
const errors = event.detail.getValidationErrorsForInput({
|
|
110
|
-
attribute: s.props.attribute,
|
|
111
|
-
inputName: inputName(),
|
|
112
|
-
onMatchValidationError: s.props.onMatchValidationError
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
s.set({errors})
|
|
116
|
-
}, [])
|
|
117
|
-
|
|
118
101
|
const setForm = useCallback(() => {
|
|
119
102
|
const inputElement = inputRef().current
|
|
120
103
|
|
|
@@ -155,21 +138,25 @@ const useInput = ({props, wrapperOptions}) => {
|
|
|
155
138
|
|
|
156
139
|
const {inputProps: oldInputProps, ...restProps} = props
|
|
157
140
|
const type = inputType()
|
|
158
|
-
const inputProps = getInputProps()
|
|
159
141
|
|
|
160
|
-
|
|
161
|
-
|
|
142
|
+
s.meta.inputProps = getInputProps()
|
|
143
|
+
s.meta.inputNameWithoutId = useMemo(() => s.m.inputProps.name?.replace(/\[(.+)_id\]$/, "[$1]"), [s.m.inputProps.name])
|
|
144
|
+
|
|
145
|
+
if (!s.m.inputProps.ref) throw new Error("No input ref?")
|
|
146
|
+
if (!handleAsSelect()) s.m.inputProps.type = type
|
|
147
|
+
|
|
148
|
+
const {validationErrors} = useValidationErrors((validationError) =>
|
|
149
|
+
validationError.inputName == s.m.inputProps.name || validationError.inputName == s.m.inputNameWithoutId
|
|
150
|
+
)
|
|
162
151
|
|
|
163
152
|
const wrapperOpts = {
|
|
164
|
-
errors:
|
|
153
|
+
errors: validationErrors,
|
|
165
154
|
form: s.s.form,
|
|
166
155
|
label: label()
|
|
167
156
|
}
|
|
168
157
|
|
|
169
|
-
useEventListener(s.s.form, "validation-errors", onValidationErrors)
|
|
170
|
-
|
|
171
158
|
return {
|
|
172
|
-
inputProps,
|
|
159
|
+
inputProps: s.m.inputProps,
|
|
173
160
|
wrapperOpts,
|
|
174
161
|
restProps
|
|
175
162
|
}
|
package/src/validation-error.mjs
CHANGED
|
@@ -11,6 +11,9 @@ class ValidationError extends BaseError {
|
|
|
11
11
|
this.validationErrors = validationErrors
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
getUnhandledErrors = () => this.validationErrors.getValidationErrors().filter((validationError) => !validationError.getHandled())
|
|
15
|
+
getValidationErrors = () => digg(this, "validationErrors")
|
|
16
|
+
|
|
14
17
|
hasUnhandledErrors() {
|
|
15
18
|
const unhandledError = this.validationErrors.getValidationErrors().find((validationError) => !validationError.getHandled())
|
|
16
19
|
|
|
@@ -89,7 +89,7 @@ class ValidationErrors {
|
|
|
89
89
|
if (onMatchValidationError) {
|
|
90
90
|
return onMatchValidationError(validationError)
|
|
91
91
|
} else {
|
|
92
|
-
return validationError.matchesAttributeAndInputName(attribute, inputName
|
|
92
|
+
return validationError.matchesAttributeAndInputName(attribute, inputName)
|
|
93
93
|
}
|
|
94
94
|
})
|
|
95
95
|
|