Skip to content

Instantly share code, notes, and snippets.

@avanslaars
Last active April 13, 2016 17:59
Show Gist options
  • Save avanslaars/3121a17074c5f8d3e2f80a805a2d3fcc to your computer and use it in GitHub Desktop.
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
//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