Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(ngSubmit): expose $event to ngSubmit callback
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleycho authored and IgorMinar committed Jul 12, 2013
1 parent 09a1e7a commit 3371fc2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ function publishExternalAPI(angular){
ngPluralize: ngPluralizeDirective,
ngRepeat: ngRepeatDirective,
ngShow: ngShowDirective,
ngSubmit: ngSubmitDirective,
ngStyle: ngStyleDirective,
ngSwitch: ngSwitchDirective,
ngSwitchWhen: ngSwitchWhenDirective,
Expand Down
9 changes: 2 additions & 7 deletions src/ng/directive/ngEventDirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
var ngEventDirectives = {};
forEach(
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress'.split(' '),
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit'.split(' '),
function(name) {
var directiveName = directiveNormalize('ng-' + name);
ngEventDirectives[directiveName] = ['$parse', function($parse) {
Expand Down Expand Up @@ -224,7 +224,7 @@ forEach(
* attribute**.
*
* @element form
* @param {expression} ngSubmit {@link guide/expression Expression} to eval.
* @param {expression} ngSubmit {@link guide/expression Expression} to eval. (Event object is available as `$event`)
*
* @example
<doc:example>
Expand Down Expand Up @@ -264,8 +264,3 @@ forEach(
</doc:scenario>
</doc:example>
*/
var ngSubmitDirective = ngDirective(function(scope, element, attrs) {
element.on('submit', function() {
scope.$apply(attrs.ngSubmit);
});
});
17 changes: 17 additions & 0 deletions test/ng/directive/ngEventDirsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,22 @@ describe('event directives', function() {
browserTrigger(element.children()[0]);
expect($rootScope.submitted).toEqual(true);
}));

it('should expose event on form submit', inject(function($rootScope, $compile) {
$rootScope.formSubmission = function(e) {
if (e) {
$rootScope.formSubmitted = 'foo';
}
};

element = $compile('<form action="" ng-submit="formSubmission($event)">' +
'<input type="submit"/>' +
'</form>')($rootScope);
$rootScope.$digest();
expect($rootScope.formSubmitted).not.toBeDefined();

browserTrigger(element.children()[0]);
expect($rootScope.formSubmitted).toEqual('foo');
}));
});
});

0 comments on commit 3371fc2

Please sign in to comment.