user675712 user675712 - 1 month ago 7
AngularJS Question

Angularjs default action when Enter key is pressed

My understanding with forms, is that if the form has an ng-submit action associated with it, then pressing the Enter key would invoke that action, typically mimicking the click of the form's "submit" button. I have a form that does not have have a button, but a custom image of a button within a div tag and the div tag has the ng-click action. When I press Enter, nothing happens. What am I missing?

BKM BKM
Answer

Make your button type submit and add a class attribute and style your button to make it an image like:

<form ng-submit="someAction()">
 <button type="submit" class="submitbutton">Submit</button>
</form>

And do style your button in css like:

.submitbutton {
  background:url('....') // your custom image
}

Then your custom image will act as the submit button and invoke the form action when click the enter key.