Angular-UI $dialog 和表单在输入键时提交 [英] Angular-UI $dialog and form submit on enter key

查看:24
本文介绍了Angular-UI $dialog 和表单在输入键时提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在 AngularJS 中处理对话框中的 Enter 键的推荐方法是放置一个 <form>标签和对话框内的提交按钮.

From what I can see, the recomended way to handle enter key in dialogs in AngularJS is to place a <form> tag and a submit button inside the dialog.

很公平,但是如果您使用 Angular-UI 和他们的 $dialog 服务,那么在按下 Enter 时表单将简单地以静默方式关闭.没办法拦截.即使您将处理程序附加到 ng-click 或 ng-submit,表单也会关闭而不会返回任何结果.

Fair enough, but if you use Angular-UI and their $dialog service, the form will simply close silently when pressing enter. no way to intercept that. even if you attach handlers to ng-click or ng-submit, the form will just close w/o returning any result.

我还有什么需要做的吗

解决了它,我必须明确指定我的取消"按钮是按钮"类型.好像默认是提交"?

Solved it, I had to specify explicitly that my "cancel" button was of type "button". Seems like it defaults to "submit" ?

所以除了我的 html 表单技能外,没有真正的问题:)

So there was no real problem except for my html form skills :)

推荐答案

回答我自己的问题.按钮似乎默认提交(?),如果我明确地将它们设置为 type="button" 那么它们在表单输入字段中按下 Enter 时不会触发回发.

To answer my own question. Buttons seems to default to submit(?) and if I explicitly set them to type="button" then they will not trigger postback when pressing enter in an form input field.

<form>
     <input type="text" ... />
     <button type="button" ng-click=...>Cancel</button>
     <button type="submit" ng-click=...>OK</button>
</form>

这样,在输入字段中按下回车键将触发确定按钮的 ng-click.

this way, pressing the enter key in the input field will trigger the ng-click for the OK button.

正如你们 html 黑客已经理解的那样,这实际上与对话框或 angularjs 无关,这是一个 html 表单问题和我缺乏网络技能......

And as you html hackers have already understood, this had nothing to do with dialogs nor angularjs really, it was a html form issue and my lack of web skills...

这篇关于Angular-UI $dialog 和表单在输入键时提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆