AngularJS:形式触发器中的所有按钮提交? [英] AngularJS: All buttons inside form triggers submit?
问题描述
我提前道歉,如果这是覆盖在这个文档中,我似乎无法找到它。
我有一个使用几个按钮,因为我使用Twitter的引导一个pretty简单的形式。问题是,单击窗体任何按钮,似乎触发提交事件的角度:在我的形式存在,其中我用的是规定属性的多个输入的字段等点击任何按钮会打开一个对话框称场需要。这是一切都很好,但我只希望当用户点击的实际提交按钮验证发生。
我已经尝试设置NG-提交给一个函数,迄今只有返回false,但这似乎没有任何效果。
更新:我发现利用使用事件preventDefault一个指令一个临时的解决方法()。然而,这似乎有点过分,也意味着我必须将其附加到每个按钮。
< DIV CLASS =排液>
< DIV CLASS =span12>
<形式NG提交=的onsubmit()级=形横>
< DIV CLASS =排液>
< DIV CLASS =span12>
< DIV CLASS =武士刀 - 技术员形式>
< DIV CLASS =控制组>
<标签类=控制标签> TEKNIKER
< DIV CLASS =控制>
< DIV CLASS =输入追加>
<输入类型=文本级=SPAN2/>
< DIV CLASS =BTN-组>
<! - 触发的onsubmit - >
<按键数据拨动=下拉菜单级=BTN下拉拨动> Velg<跨度类=插入符号>< / SPAN> < /按钮>
< UL类=下拉菜单>
<立GT;&Kake的LT; /李>
<立GT;烘烤< /李>
< / UL>
< / DIV>
< / DIV>
< / DIV>
< /标签>
< / DIV>
< / DIV>
< / DIV>
< / DIV>
< DIV CLASS =排液>
< DIV CLASS =span12>
<! - 触发的onsubmit - >
<按钮式=提交>< /按钮>
< / DIV>
< / DIV>
< / DIV>
< /表及GT;
< / DIV>
< / DIV>
您应该尝试设置键入按钮=按钮
。
这个问题进入细节至于什么这样做。
I apologize in advance if this is covered in the docs, but I can't seem to find it.
I have a pretty straightforward form which uses several buttons as I'm using twitter bootstrap. The problem is that clicking any of the buttons in the form seems to trigger a submit event to angular: In my form there are several input fields in which I use the "require" attribute and so clicking any button opens a dialog saying the field is required. This is all well and good, except I only want the validation to take place when the user clicks the actual submit button.
I have tried setting the ng-submit to a function which so far only returns false, but this did not seem to have any effect.
Update: I've found a temporary workaround using a directive which uses event.preventDefault(). However this seems a bit excessive and also means I have to attach it to every button.
<div class="row-fluid">
<div class="span12">
<form ng-submit="onSubmit()" class="form-horizontal">
<div class="row-fluid">
<div class="span12">
<div class="katana-technician-form">
<div class="control-group">
<label class="control-label">Tekniker
<div class="controls">
<div class="input-append">
<input type="text" class="span2" />
<div class="btn-group">
<!-- Triggers onSubmit-->
<button data-toggle="dropdown" class="btn dropdown-toggle">Velg<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Kake</li>
<li>Bake</li>
</ul>
</div>
</div>
</div>
</label>
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<!-- Triggers onSubmit-->
<button type="submit"></button>
</div>
</div>
</div>
</form>
</div>
</div>
You should try setting type="button"
on the buttons.
This question goes into detail as to what this does.
这篇关于AngularJS:形式触发器中的所有按钮提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!