javascript - Angular+Jquery - Programmatic form submit causes redirect -
i'm trying write form has ngssubmit. pressing enter , clicking submit button works expected (calling method provided ng-submit , that's that).
however, want in cases preprocessing before submitting, tried using jquery's submit() programmatically trigger submit.
this causes ng-submit handler fire, , sends form refreshing whole page.
any ideas how around or why happens???
example here ("click me" shows bad behavior) http://jsfiddle.net/yf5tf/
<form ng-app="myapp" ng-submit="submitme()" ng-controller="myctrl"> <input type="text" ng-model="value"></input> <input type="submit" value="go!"></input> <div ng-click="progsubmit()">click me</div> </form> angular.module('myapp', []) .controller('myctrl', function($scope, $element, $timeout) { $scope.submitme = function() { alert ("hi"); }; $scope.progsubmit = function() { $timeout(function() { var inputelem = $element.find("input"); angular.element(inputelem[0].form).submit(); }, 0); }; });
thanks, yaron
so... in case has same issue.
the solution trigger submit using jquery. ideally be:
angular.element($scope.inputelem[0].form).trigger('submit');
however, there bug in angular, current work around found this:
angular.element($scope.inputelem[0].form).find('[type=submit]').trigger('click');
cheers.
Comments
Post a Comment