Use submit hook instead of click hook in form example

This commit is contained in:
Tim Wisniewski
2016-05-26 07:02:23 -04:00
parent 9b32e8fe07
commit 7faecd76ee
+5 -4
View File
@@ -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()
} }
} }