-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhybrid.ts
34 lines (30 loc) · 1.02 KB
/
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
30
31
32
33
34
import { ProxyNode, watch } from '../core'
import { queryElement, queryElementProxies } from '../selector'
// it will throw error if the selector doesn't match any elements.
let loginForm = queryElement<HTMLFormElement>('#loginForm')
let elements = queryElementProxies(
{
username: '[name=username]',
password: '[name=password]',
preview: '#preview',
reset: '[type=reset]',
submit: '[type=submit]',
},
loginForm,
)
const preview = elements.preview
const username = elements.username as ProxyNode<HTMLInputElement>
const password = elements.password as ProxyNode<HTMLInputElement>
const reset = elements.reset as ProxyNode<HTMLInputElement>
const submit = elements.submit as ProxyNode<HTMLInputElement>
watch(() => {
preview.textContent = username.value + ':' + password.value
})
watch(() => {
reset.disabled = !username.value && !password.value
submit.disabled = !username.value || !password.value
})
loginForm.addEventListener('submit', event => {
event.preventDefault()
alert('mock form submission')
})