Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs default action when Enter key is pressed

Tags:

angularjs

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?

like image 952
Lazloman Avatar asked Mar 18 '14 03:03

Lazloman


3 Answers

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.

like image 71
BKM Avatar answered Oct 17 '22 12:10

BKM


It worked for me by adding ng-submit, ng-controller & button type as submit

<form ng-submit="func()" ng-controller="MyController"> <button type="submit">Submit</button </form>

like image 24
Ankita Gupta Avatar answered Oct 17 '22 13:10

Ankita Gupta


if your form contains md-autofocus - remove it. worked for me.

like image 21
Moria Cohavi Avatar answered Oct 17 '22 11:10

Moria Cohavi