AngularJS:形式触发器中的所有按钮提交?

编程入门 行业动态 更新时间:2024-10-27 06:28:16
本文介绍了AngularJS:形式触发器中的所有按钮提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我提前道歉,如果这是覆盖在这个文档中,我似乎无法找到它。

我有一个使用几个按钮,因为我使用Twitter的引导一个pretty简单的形式。问题是,单击窗体任何按钮,似乎触发提交事件的角度:在我的形式存在,其中我用的是规定属性的多个输入的字段等点击任何按钮会打开一个对话框称场需要。这是一切都很好,但我只希望当用户点击的实际提交按钮验证发生。

我已经尝试设置NG-提交给一个函数,迄今只有返回false,但这似乎没有任何效果。

更新:我发现利用使用事件preventDefault一个指令一个临时的解决方法()。然而,这似乎有点过分,也意味着我必须将其附加到每个按钮。

< D​​IV CLASS =排液>    < D​​IV CLASS =span12>        <形式NG提交=的onsubmit()级=形横>            < D​​IV CLASS =排液>                < D​​IV CLASS =span12>                    < D​​IV CLASS =武士刀 - 技术员形式>                        < D​​IV CLASS =控制组>                            <标签类=控制标签> TEKNIKER                                < D​​IV CLASS =控制>                                    < D​​IV CLASS =输入追加>                                        <输入类型=文本级=SPAN2/>                                        < D​​IV CLASS =BTN-组>                                            <! - 触发的onsubmit - >                                            <按键数据拨动=下拉菜单级=BTN下拉拨动> Velg<跨度类=插入符号>< / SPAN>                                            < /按钮>                                            < UL类=下拉菜单>                                                <立GT;&Kake的LT; /李>                                                <立GT;烘烤< /李>                                            < / UL>                                        < / DIV>                                    < / DIV>                                < / DIV>                            < /标签>                        < / DIV>                    < / DIV>                < / DIV>            < / DIV>            < D​​IV CLASS =排液>                < D​​IV 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:形式触发器中的所有按钮提交?

本文发布于:2023-11-12 04:58:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   器中   形式   AngularJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!