Last active
April 13, 2016 17:59
-
-
Save avanslaars/3121a17074c5f8d3e2f80a805a2d3fcc to your computer and use it in GitHub Desktop.
"Fix" For clearing an input field after submit using an update hook in Snabbdom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Run it here: http://www.webpackbin.com/VJBxSuP1W | |
import Motorcycle from '@motorcycle/core' | |
import {div, label, input, hr, h1, makeDOMDriver} from '@motorcycle/dom'; | |
import most from 'most' | |
function main(sources) { | |
const input$ = sources.DOM.select('.field').events('input') | |
const click$ = sources.DOM.select('.btn').events('click') | |
const sinks = { | |
DOM: input$ | |
.sampleWith(click$) | |
.map(ev => ev.target.value) | |
.startWith('') | |
.map(name => | |
div([ | |
label('Name:'), | |
//Reset the text field value on each render | |
input('.field', {attrs: {type: 'text'}, hook:{ | |
update: (o, n) => n.elm.value = "" | |
}}), | |
input('.btn', {attrs:{type:'submit',value:'Save'}}), | |
hr(), | |
h1('Hello ' + name) | |
]) | |
) | |
}; | |
return sinks; | |
} | |
Motorcycle.run(main, { DOM: makeDOMDriver('#app') }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment