I'm trying to write a form which has ngsSubmit. Pressing Enter and clicking the submit button works as expected (calling the method I provided for ng-submit and that's that).
However, I also want in some cases to do some preprocessing before actually submitting, so I tried using JQuery's submit() to programmatically trigger the submit.
This causes the ng-submit handler to fire, AND also sends the form normally refreshing the whole page.
Any ideas how to get around this or why it happens???
Example here ("click me" shows the 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