[ACCEPTED]-How to prevent form submit on enter key press using angular JS?-angularjs

Accepted answer
Score: 18

This response is a little late, but this 7 issue just tripped my team up this afternoon 6 - hopefully our experience will help others.

Merely 5 adding attribute type="button" to your button object 4 will do the trick - no need for any other 3 changes. This is actually a good attribute 2 to add to any button on your form that is 1 not expressly a form submit button.

<button class="close" type="button" ng-click="toggleForm()" title="Close form">&times;</button>
Score: 2

Remove the 'type="submit"' from the add button and use 2 ng-click="addTranslation()" instead. Also remove ng-submit from the form tag as 1 follows

<button class="btn btn-primary btn-xs" ng-click="toggleForm()">Add translation</button>
<form class="block form-inline" id="translation_form" ng-show="form">
        Enter a new translation for this text in {{language | uppercase}}:
        <button class="close" ng-click="toggleForm()" title="Close form">&times;</button>
    <hr />
    <div class="form-group">
        <input type="text" class="form-control" ng-model="formData.text" />
        <button class="btn btn-primary btn-sm" ng-click="addTranslation()">Add</button>

More Related questions