unhammer
unhammer

Reputation: 4700

How do you use <datalist> with IHP?

Is there some builtin method for HTML text field completion with a simple <datalist> in IHP? E.g. as in https://stackoverflow.com/a/19779010/69663

Upvotes: 1

Views: 30

Answers (1)

unhammer
unhammer

Reputation: 4700

Grepping the IHP code it seems not, but it was easy to just do it "manually":

instance View NewView where
    html NewView { .. }  = [hsx|
        {renderForm thing}
        <datalist id="languages">
          {forEach languages renderOption}
        </datalist>
|]

renderForm :: Thing -> Html
renderForm thing = formFor thing [hsx|
    {(textField #language) { additionalAttributes = [("list", "languages")]}}
|]

renderOption :: Text -> Html
renderOption value = [hsx| <option value={value}/> |]

Upvotes: 3

Related Questions