noph-ui 0.13.3 → 0.13.4
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.
|
@@ -18,13 +18,35 @@
|
|
|
18
18
|
placeholder = ' ',
|
|
19
19
|
element = $bindable(),
|
|
20
20
|
inputElement = $bindable(),
|
|
21
|
+
reportValidity = $bindable(),
|
|
22
|
+
checkValidity = $bindable(),
|
|
21
23
|
...attributes
|
|
22
24
|
}: TextFieldProps = $props()
|
|
23
25
|
|
|
24
26
|
let errorRaw: boolean = $state(error)
|
|
25
27
|
let errorTextRaw: string = $state(errorText)
|
|
26
28
|
let focusOnInvalid = $state(true)
|
|
27
|
-
let
|
|
29
|
+
let doValidity = $state(false)
|
|
30
|
+
|
|
31
|
+
reportValidity = () => {
|
|
32
|
+
if (inputElement) {
|
|
33
|
+
const valid = inputElement.reportValidity()
|
|
34
|
+
if (valid) {
|
|
35
|
+
errorRaw = error
|
|
36
|
+
errorTextRaw = errorText
|
|
37
|
+
}
|
|
38
|
+
return valid
|
|
39
|
+
}
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
checkValidity = () => {
|
|
44
|
+
if (inputElement) {
|
|
45
|
+
return inputElement.checkValidity()
|
|
46
|
+
}
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
|
|
28
50
|
$effect(() => {
|
|
29
51
|
errorRaw = error
|
|
30
52
|
errorTextRaw = errorText
|
|
@@ -37,7 +59,7 @@
|
|
|
37
59
|
value = ''
|
|
38
60
|
})
|
|
39
61
|
inputElement.addEventListener('input', () => {
|
|
40
|
-
|
|
62
|
+
doValidity = true
|
|
41
63
|
})
|
|
42
64
|
inputElement.addEventListener('invalid', (event) => {
|
|
43
65
|
event.preventDefault()
|
|
@@ -53,13 +75,10 @@
|
|
|
53
75
|
}
|
|
54
76
|
})
|
|
55
77
|
|
|
56
|
-
inputElement.addEventListener('blur', (
|
|
57
|
-
|
|
58
|
-
currentTarget: HTMLInputElement | HTMLTextAreaElement
|
|
59
|
-
}
|
|
60
|
-
if (checkValidity) {
|
|
78
|
+
inputElement.addEventListener('blur', () => {
|
|
79
|
+
if (doValidity) {
|
|
61
80
|
focusOnInvalid = false
|
|
62
|
-
if (
|
|
81
|
+
if (checkValidity()) {
|
|
63
82
|
errorRaw = error
|
|
64
83
|
errorTextRaw = errorText
|
|
65
84
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TextFieldProps } from './types.ts';
|
|
2
|
-
declare const TextField: import("svelte").Component<TextFieldProps, {}, "element" | "value" | "inputElement">;
|
|
2
|
+
declare const TextField: import("svelte").Component<TextFieldProps, {}, "element" | "value" | "inputElement" | "reportValidity" | "checkValidity">;
|
|
3
3
|
type TextField = ReturnType<typeof TextField>;
|
|
4
4
|
export default TextField;
|
|
@@ -13,6 +13,8 @@ interface FieldProps {
|
|
|
13
13
|
noAsterisk?: boolean;
|
|
14
14
|
element?: HTMLSpanElement;
|
|
15
15
|
inputElement?: HTMLInputElement | HTMLTextAreaElement;
|
|
16
|
+
reportValidity?: () => boolean;
|
|
17
|
+
checkValidity?: () => boolean;
|
|
16
18
|
}
|
|
17
19
|
export interface InputFieldProps extends HTMLInputAttributes, FieldProps {
|
|
18
20
|
type?: 'text' | 'password' | 'email' | 'number' | 'search' | 'tel' | 'url' | 'datetime-local';
|