react-hook-core 0.4.21 → 0.4.22
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/state.ts +7 -3
package/package.json
CHANGED
package/src/state.ts
CHANGED
|
@@ -16,7 +16,11 @@ export function getDecimalSeparator(ele: HTMLInputElement): string {
|
|
|
16
16
|
|
|
17
17
|
const r1 = / |,|\$|€|£|¥|'|٬|،| /g
|
|
18
18
|
const r2 = / |\.|\$|€|£|¥|'|٬|،| /g
|
|
19
|
-
export function updateState<T>(
|
|
19
|
+
export function updateState<T>(
|
|
20
|
+
e: ChangeEvent<HTMLInputElement, HTMLInputElement> | ChangeEvent<HTMLTextAreaElement, HTMLTextAreaElement>,
|
|
21
|
+
o: T,
|
|
22
|
+
setObj: (v: React.SetStateAction<T>) => void,
|
|
23
|
+
) {
|
|
20
24
|
const ctrl = e.target
|
|
21
25
|
const dataField = ctrl.getAttribute("data-field")
|
|
22
26
|
const field = dataField ? dataField : ctrl.name
|
|
@@ -36,7 +40,7 @@ export function updateState<T>(e: ChangeEvent<HTMLInputElement, HTMLInputElement
|
|
|
36
40
|
if (type === "text") {
|
|
37
41
|
const datatype = ctrl.getAttribute("data-type")
|
|
38
42
|
if (datatype === "number" || datatype === "integer") {
|
|
39
|
-
const decimalSeparator = getDecimalSeparator(ctrl)
|
|
43
|
+
const decimalSeparator = getDecimalSeparator(ctrl as HTMLInputElement)
|
|
40
44
|
const v0: string = ctrl.value
|
|
41
45
|
const v = decimalSeparator === "," ? v0.replace(r2, "") : v0.replace(r1, "")
|
|
42
46
|
const val = isNaN(v as any) ? undefined : parseFloat(v)
|
|
@@ -53,7 +57,7 @@ export function updateState<T>(e: ChangeEvent<HTMLInputElement, HTMLInputElement
|
|
|
53
57
|
value.includes(ctrl.value) ? (value = value.filter((v: string) => v !== ctrl.value)) : value.push(ctrl.value)
|
|
54
58
|
model[field] = value
|
|
55
59
|
} else {
|
|
56
|
-
const v = valueOfCheckbox(ctrl)
|
|
60
|
+
const v = valueOfCheckbox(ctrl as HTMLInputElement)
|
|
57
61
|
model[field] = v
|
|
58
62
|
}
|
|
59
63
|
} else if (type === "radio") {
|