Skip to content

Commit 91e23c2

Browse files
committed
exit early from setting the loading state if attributes are missing
1 parent b0ae7ef commit 91e23c2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ function setLoadingState(event: Event) {
9999
const input = event.currentTarget
100100
if (!(input instanceof HTMLInputElement)) return
101101

102+
const autoCheckElement = input.closest('auto-check')
103+
if (!(autoCheckElement instanceof AutoCheckElement)) return
104+
105+
const src = autoCheckElement.src
106+
const csrf = autoCheckElement.csrf
107+
const state = states.get(autoCheckElement)
108+
109+
// If some attributes are missing we want to exit early and make sure that the element is valid.
110+
if (!src || !csrf || !state) {
111+
return
112+
}
113+
102114
let message = 'Verifying…'
103115
const setValidity = text => (message = text)
104116
input.dispatchEvent(
@@ -108,8 +120,7 @@ function setLoadingState(event: Event) {
108120
})
109121
)
110122

111-
const autoCheckElement = input.closest('auto-check')
112-
if (autoCheckElement instanceof AutoCheckElement && autoCheckElement.required) {
123+
if (autoCheckElement.required) {
113124
input.setCustomValidity(message)
114125
}
115126
}

0 commit comments

Comments
 (0)