Skip to content

Instantly share code, notes, and snippets.

@paldepind
Last active February 5, 2016 01:56
Show Gist options
  • Save paldepind/f8120090f42ba572c4d1 to your computer and use it in GitHub Desktop.
Save paldepind/f8120090f42ba572c4d1 to your computer and use it in GitHub Desktop.
Helper function for creating forms in Reflex. The default of forms is prevented. A submit event and child is returned.
import GHCJS.DOM.EventM (event, preventDefault)
import GHCJS.DOM.Element
form :: MonadWidget t m => m a -> m (Event t (), a)
form child = do
(form, ch) <- el' "form" child
submit <- wrapDomEvent (_el_element form) elementOnsubmit (void $ preventDefault)
performEvent_ (return () <$ submit)
return (submit, ch)
(submitAppend, appendText) <- form $ do
appendText <- textInput def
button "Append"
return appendText
appendText <- return $ tag (current (_textInput_value appendText)) submitAppend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment