Skip to content

Instantly share code, notes, and snippets.

@ericbmerritt
Created January 20, 2018 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericbmerritt/727b82d490408aa5132615139e84f46f to your computer and use it in GitHub Desktop.
Save ericbmerritt/727b82d490408aa5132615139e84f46f to your computer and use it in GitHub Desktop.
https://git.gnu.io/chreekat/yesod/commit/41faf62094ad7077573de797599c742ff9401c4e
> mkYesod "HW" [$parseRoutes|
> / RootR GET
> /form FormR
> /static StaticR Static hwStatic
> /autocomplete AutoCompleteR GET
----
handleFormR = do
> (res, form, enctype, nonce) <- runFormPost $ fieldsToTable $ (,,,,,,,,)
> <$> stringField "My Field" Nothing
> <*> stringField "Another field" (Just "some default text")
> <*> intField "A number field" (Just 5)
> <*> jqueryDayField def "A day field" Nothing
> <*> timeField "A time field" Nothing
> <*> boolField "A checkbox" (Just False)
> <*> jqueryAutocompleteField AutoCompleteR "Autocomplete" Nothing
> <*> nicHtmlField "HTML"
> (Just $ string "You can put <rich text> here")
> <*> maybeEmailField "An e-mail addres" Nothing
> let mhtml = case res of
> FormSuccess (_, _, _, _, _, _, _, x, _) -> Just x
> _ -> Nothing
> defaultLayout $ do
> addCassius [$cassius|
> .tooltip
----
> getAutoCompleteR :: Handler RepJson
> getAutoCompleteR = do
> term <- runFormGet' $ stringInput "term"
> jsonToRepJson $ jsonList
> [ jsonScalar $ unpack term ++ "foo"
> , jsonScalar $ unpack term ++ "bar"
> , jsonScalar $ unpack term ++ "baz"
> ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment