Use submit hook instead of click hook in form example
This commit is contained in:
@@ -419,7 +419,7 @@ const app = choo()
|
|||||||
|
|
||||||
function view (params, state, send) {
|
function view (params, state, send) {
|
||||||
return choo.view`
|
return choo.view`
|
||||||
<form id="#login-form">
|
<form onsubmit=${onSubmit}>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label>username</label>
|
<label>username</label>
|
||||||
<input type="text" name="username" autofocus>
|
<input type="text" name="username" autofocus>
|
||||||
@@ -428,13 +428,14 @@ function view (params, state, send) {
|
|||||||
<label>password</label>
|
<label>password</label>
|
||||||
<input type="password" name="password">
|
<input type="password" name="password">
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<input type="submit" value="Submit" onClick=${onClick}>
|
<input type="submit" value="Submit">
|
||||||
</form>
|
</form>
|
||||||
`
|
`
|
||||||
|
|
||||||
function onClick () {
|
function onSubmit (e) {
|
||||||
const data = getFormData(document.querySelector('#login-form'))
|
const data = getFormData(e.target)
|
||||||
send('post', { payload: data })
|
send('post', { payload: data })
|
||||||
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user