Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form ng-click is triggering ng-submit

Tags:

angularjs

I have a form whose ng-submit is to move to the next question.

        <form ng-submit="BC.next()" novalidate>
            <input type="submit" value="Next Question"/>
            <button id="previous" ng-click="BC.previous()">Previous Question</button>

However, whenever I click on the previous button, after executing, it then triggers the BC.next() I'm so confused, does anyone know why this is happening? I even tried closing the <input type="submit"> tag with a </input> but that didn't fix it.

like image 967
Noitidart Avatar asked Sep 25 '15 16:09

Noitidart


1 Answers

Make sure that all other button in the form that are not submitting it will be from type="button".

 <form ng-submit="BC.next()" novalidate>
            <input type="submit" value="Next Question"/>
            <button type="button" id="previous" ng-click="BC.previous()">Previous Question</button>

You can see the details: How to prevent buttons from submitting forms

TL;DR for the post: HTML5 defaults <button> as <button type="submit"> so you need to change this manually.

like image 91
Shikloshi Avatar answered Oct 12 '22 03:10

Shikloshi