Opa:提交表单时防止页面重新加载
在 Opa 中,如何防止提交表单时重新加载页面?当按下提交时,我想执行一些客户端验证,并且仅在验证通过时才提交表单。
我正在使用此表单:
<form onready={_ -> ready()} id=#form_id>
<input type="submit" value="Submit" />
</form>
此函数在提交时成功记录其消息,但仍重新加载页面:
ready() : void =
do ignore(Dom.bind(#form_id, {submit}, ( _ -> Log.notice("submit","submitted"))))
此函数无法记录其消息并重新加载页面:
ready() : void =
do ignore(Dom.bind_with_options(#form_id, {submit}, ( _ -> Log.notice("submit","submitted")), [{prevent_default}]))
我避免使用 WFormBuilder
因为我需要对表单的 html 和验证错误消息进行细粒度控制(当我尝试时,这在 WFormBuilder
中似乎不是一个选项)。
感谢您的帮助。
In Opa, how can I prevent a page reload when a form is submitted? When submit is pressed, I want to perform some client-side validation and only submit the form if validation passes.
I'm working with this form:
<form onready={_ -> ready()} id=#form_id>
<input type="submit" value="Submit" />
</form>
This function successfully logs its message on submit, but still reloads the page:
ready() : void =
do ignore(Dom.bind(#form_id, {submit}, ( _ -> Log.notice("submit","submitted"))))
This function fails to log its message and reloads the page:
ready() : void =
do ignore(Dom.bind_with_options(#form_id, {submit}, ( _ -> Log.notice("submit","submitted")), [{prevent_default}]))
I'm avoiding using WFormBuilder
because I need fine grained control over the html of the form and the validation error messages (which did not seem like an option in WFormBuilder
when I experimented with it).
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 源
WFormBuilder
,我在其表单 html 中找到了此属性:options:onsubmit="prevent_default"
所以代码片段具有我正在寻找的行为:
In the source of
WFormBuilder
, I found this attribute in its form html:options:onsubmit="prevent_default"
So snippet has the behavior I was looking for: