javascript - AngularJS - ngClick is blocking submit key action -


the user of web should enter simple code using buttons in form , after should click ok or hit enter , continue proccess.

the thing enter key not submiting form, executing other method called ng-click. how can avoid enter key call ng-click method?

myapp.js

var myapp = angular.module('myapp',[]);  myapp.controller('myformcontroller', ['$scope', function ($scope){     // procesing data form.     $scope.signin = function () {     } }]);  myapp.controller('mycontroller', ['$scope', function ($scope){    $scope.do = function() {        alert('ng-click pressed!');    } }]); 

myform.html

<div ng-controller="myformcontroller">      <form name="myform"           role="form"            ng-submit="signin()"            novalidate>          <input type="text"/>          <div ng-controller="mycontroller">             <a href="javascript:void(0);" ng-click="do()">                 clickme!             </a>         </div>          <button type="submit">ok</button>     </form>  </div> 

press click me , hit enter key after on my fiddle

you can ommit html rules jquery. add id form , button first:

<form id="mydiv" name="myform"     role="form"      ng-submit="signin()"      novalidate>      <div ng-controller="mycontroller">        <a href="javascript:void(0);" ng-click="do()">           <img src="img/a-letter.png" alt="">         </a>     </div>      <button id="mydiv2" type="submit">ok</button> </form> 

and set listener on enter up:

$("#mydiv").keyup(function(event){ if(event.keycode == 13){     $("#mydiv2").click(); } }); 

so it's not elegant, can submit form simulating click on enter pressed.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -