2015-08-24 29 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>