角UI $对话框,表单上输入键提交 [英] Angular-UI $dialog and form submit on enter key
问题描述
从我所看到的,recomended方式来处理在AngularJS对话进入关键是要放置<形式为GT;标签和对话框内提交按钮。
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.
很公平,但如果你使用角UI和$对话框的服务,表单将只需关闭时默默pressing进入。没办法拦截。
即使你附加处理程序NG-点击或NG-提交表单就会闭合W / O返回任何结果。
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.
有没有别的东西,我需要做的。
Is there something else I need to do
解决了这个问题,我必须明确指定我的取消按钮是类型按钮的。
好像它默认为提交?
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 =按钮,然后在pressing在表单输入字段中输入他们将不会触发回发。
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>
这样,pressing回车在输入字段中键触发NG-单击确定按钮。
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...
这篇关于角UI $对话框,表单上输入键提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!