2015-08-24 34 views
3

如果在编辑后按下Enter按钮input_a,则会调用processInputA()submit()功能被省略。AngularJS:表单中的第一个按钮即使不是提交按钮,也会输入按钮按下

input_b这不会发生:即使它与input_a类似,它也可以按预期工作。按预期方式调用submit()函数。

如何防止input_a发射后的按钮?

<form class="uk-form" ng-submit="submit()"> 
    <div class="uk-form-row"> 
    <input type="text" 
      name="input_a" 
      ng-model="buffer.inputA" ng-change="reportInputATyped()" 
      class="uk-width-3-10 uk-form-small"> 
    <button ng-cloak ng-show="inputADirty" class="uk-button uk-button-small" ng-click="processInputA()">Apply</button> 
    /
    <input type="text" 
      name="input_b" 
      ng-model="buffer.inputB" ng-change="reportInputBTyped()" 
      class="uk-width-6-10 uk-form-small"> 
    <button ng-cloak ng-show="inputBDirty" class="uk-button uk-button-small" ng-click="processInputB()">Apply</button> 
    </div> 
    // ...further inputs... 
</form> 

AngularJS:http://angular-meteor.com

样式:http://getuikit.com

+0

您可以创建一个演示?很明显,为什么进入大火会提交,但第二个应该表现相同。可能有一些你没有显示的代码会与第二个输入相互作用而阻止它。 – dfsq

+0

当我在第一个输入中按下它时,它__不会触发火灾:它触发click处理程序'processInputA()'。 (但是它应该 - 火焰提交而不是)。 – ideaboxer

+0

这只是本地代码。不知道如何创建演示... – ideaboxer

回答

2

<button>元件似乎如果通过镀铬呈现为缺省类型submit的。不是我期望的直觉。

的W4Schools.com文章指出尖端:

始终指定该元素的类型的属性。不同的浏览器可能会为元素使用不同的默认类型。

http://www.w3schools.com/tags/att_button_type.asp

版本,如果处理由Chrome浏览器的工作原理:

<form class="uk-form" ng-submit="submit()"> 
    <div class="uk-form-row"> 
    <input type="text" 
      name="input_a" 
      ng-model="buffer.inputA" ng-change="reportInputATyped()" 
      class="uk-width-3-10 uk-form-small"> 
    <button type="button" ng-cloak ng-show="inputADirty" class="uk-button uk-button-small" ng-click="processInputA()">Apply</button> 
    /
    <input type="text" 
      name="input_b" 
      ng-model="buffer.inputB" ng-change="reportInputBTyped()" 
      class="uk-width-6-10 uk-form-small"> 
    <button type="button" ng-cloak ng-show="inputBDirty" class="uk-button uk-button-small" ng-click="processInputB()">Apply</button> 
    </div> 
    // ...further inputs... 
</form>