How to use Html.form in ELM form?

会有一股神秘感。 提交于 2019-12-11 03:28:07

问题


I want to make an HTML form that actually uses the [form] tag in ELM. None of the example online do this -- they simply put the [input] tags in a [div] instead of a [form]

When I try switching my Elm app to a [form], my [input type=sumbit] tags don't seem to call back to Elm. The submit tries to leave the page and add a "?" to my url.

Any hints on how to do this?

WHY: I want to be a using [form], so I can use the "required" attribute on some [input] fields. This is just one part of my validation, but I like the UI that "required" tag presents.


回答1:


You should use onSubmit in Html.form.

Here is the example.

Html.form [ onSubmit Submit ]
  [ input
    [ type' "submit"
    , value "click here to submit"
    ]
    []
  ]


来源:https://stackoverflow.com/questions/40311080/how-to-use-html-form-in-elm-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!