I have a website with tons of Formuars and I allways do the same thing before and after submitting a form. So I want to write a directive, which hide the magic which must be done.
I've the folloing markup (the ng-click is only to shorten the code. In the real code it will be hidden inside a template):
<form class="form" name="form" ng-submit="customSubmit()">
<input ... />
<my-submit ng-click="fakeSubmit()" type="button">Submit</my-submit>
</form>
The mySubmit Directive should look something like this:
module.directive('MySubmit', function ($state) {
return {
restrict: 'E',
controller: function ($scope) {
$scope.fakeSubmit = function () {
// deactivate button
var result = magicThing.callSubmitFromForm();
// activate button
// throw event, that form was submitted
return false;
}
}
};
});
In the directive controller there is the line magicThing.callSubmitFromForm(). This should trigger the ngSubmit magic with validators etc and then call the Method customSubmit(). I also want to have the result of the method customSubmit, which might be a Callback or something else.
As I mentioned above, I want to write a generic directive, so I don't know the function which I call here customSubmit()
Does anyone have in idea how to do this?