Skip to content

Instantly share code, notes, and snippets.

@agocorona
Last active August 29, 2015 14:18
Show Gist options
  • Save agocorona/caf924d931c5d0406022 to your computer and use it in GitHub Desktop.
Save agocorona/caf924d931c5d0406022 to your computer and use it in GitHub Desktop.
A special form with some tricks in hplayground . compile it with http://tryplayg.herokuapp.com/
import Haste.HPlay.View
import Prelude hiding (div)
main= runBody $ do
let id= atr "id"
type_= atr "type"
name= atr "name"
value= atr "value"
r <-div ! id "selectors" <<<(
( button "Form A" `pass` OnClick >> return True) <|>
( button "Form B" `pass` OnClick >> return False))
wraw hr
div ! id "body" <<< do
out <-
case r of
True -> do
Left <$>((,) <$> inputInt (Just 10) ! type_ "number" <++ br
<*> getRadio[\v -> label (0 :: Int) ++> setRadio (0 :: Int) v
,\v -> label (1 :: Int) ++> setRadio 1 v]
<++ (do br ; div ! atr "class" "message" $ noHtml)
) `validate` (\(v,_) -> return $ if v< 100 then Nothing else Just $ toElem "wrong")
False ->
Right <$> inputString Nothing ! atr "placeholder" "type something"
<** br
++> do
button "cancel" `pass` OnClick
at "body" Insert (wraw noHtml)
wraw . forElems "#selectors" $ this ! atr "style" "background-color:red"
<** wraw ( button "submit") `fire` OnClick
<++ hr
wprint out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment