-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhybrid.ts
29 lines (25 loc) · 981 Bytes
/
hybrid.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { watch } from '../core'
import { queryElement, queryElementProxies } from '../selector'
// it will throw error if the selector doesn't match any elements.
let loginForm = queryElement('form#loginForm') // infer to be HTMLFormElement <- "form" tag name
let { username, password, showPw, reset, submit } = queryElementProxies(
{
username: 'input[name=username]', // infer to be ProxyNode<HTMLInputElement> <- "input" tagName
password: '[name=password]', // fallback to be ProxyNode<HTMLInputElement> <- "[name=.*]" attribute
showPw: 'input#show-pw[type=checkbox]',
reset: 'input[type=reset]',
submit: 'input[type=submit]',
},
loginForm,
)
watch(() => {
password.type = showPw.checked ? 'text' : 'password'
})
watch(() => {
reset.disabled = !username.value && !password.value
submit.disabled = !username.value || !password.value
})
loginForm.addEventListener('submit', event => {
event.preventDefault()
alert('mock form submission')
})