javascript - Submit form while key press in Angular JS -
i have login form follows. login controller called when login button clicked , working fine. need same function called on "enter" key press after entering username , password.
<form class="form-horizontal"> <fieldset> <div class="form-group"> <input type="text" class="form-control input-lg input-round text-center" placeholder="username" ng-model="uservals"> </div> <div class="form-group"> <input type="password" class="form-control input-lg input-round text-center" placeholder="password" ng-model="passvals"> </div> <div class="form-group"> <a href="#/" class="btn btn-primary btn-lg btn-round btn-block text-center" ng-click="log_me()">log in</a> </div> </fieldset> </form>
controller
var mysession = ''; function logincontroller($scope, $http, $cookiestore, $location) { $scope.sess_id = mysession; var token = $cookiestore.get('token'); var conid = $cookiestore.get('cont_id'); var exid = $cookiestore.get('ex_id'); $scope.log_me = function() { $scope.login_me = []; var login_un = $scope.uservals; var login_pwd = $scope.passvals; var logs_me = "http://www.vb.com/login.html?username=" + login_un + "&password=" + login_pwd; $http.get(logs_me) .success(function(response) { $cookiestore.put('token', response.token); $cookiestore.put('ex_id', response.exid); $cookiestore.put('cont_id', response.contactid); $cookiestore.put('email', response.email); $cookiestore.put('name', response.name); mysession = response.ss_id; if (response.status == "failure") { $('.login_error').show(); $('.login_error').html('invalid username or password'); $('.login_error').delay(4000).fadeout(); $('.loading').hide(); } else { $('.page-signin').hide(); $('.signin-header').hide(); $location.path('/dashboard'); } }); } }
change form this;
<form class="form-horizontal" ng-submit="log_me()">
and update button submit button below;
<input type="submit" class="btn btn-primary btn-lg btn-round btn-block text-center" value="log in"/>
this automatically submit form when click enter key.
Comments
Post a Comment