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

Commit 3371fc2

Browse files
wesleychoIgorMinar
authored andcommitted
fix(ngSubmit): expose $event to ngSubmit callback
1 parent 09a1e7a commit 3371fc2

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/AngularPublic.js

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ function publishExternalAPI(angular){
8888
ngPluralize: ngPluralizeDirective,
8989
ngRepeat: ngRepeatDirective,
9090
ngShow: ngShowDirective,
91-
ngSubmit: ngSubmitDirective,
9291
ngStyle: ngStyleDirective,
9392
ngSwitch: ngSwitchDirective,
9493
ngSwitchWhen: ngSwitchWhenDirective,

src/ng/directive/ngEventDirs.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
var ngEventDirectives = {};
3939
forEach(
40-
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress'.split(' '),
40+
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit'.split(' '),
4141
function(name) {
4242
var directiveName = directiveNormalize('ng-' + name);
4343
ngEventDirectives[directiveName] = ['$parse', function($parse) {
@@ -224,7 +224,7 @@ forEach(
224224
* attribute**.
225225
*
226226
* @element form
227-
* @param {expression} ngSubmit {@link guide/expression Expression} to eval.
227+
* @param {expression} ngSubmit {@link guide/expression Expression} to eval. (Event object is available as `$event`)
228228
*
229229
* @example
230230
<doc:example>
@@ -264,8 +264,3 @@ forEach(
264264
</doc:scenario>
265265
</doc:example>
266266
*/
267-
var ngSubmitDirective = ngDirective(function(scope, element, attrs) {
268-
element.on('submit', function() {
269-
scope.$apply(attrs.ngSubmit);
270-
});
271-
});

test/ng/directive/ngEventDirsSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,22 @@ describe('event directives', function() {
2121
browserTrigger(element.children()[0]);
2222
expect($rootScope.submitted).toEqual(true);
2323
}));
24+
25+
it('should expose event on form submit', inject(function($rootScope, $compile) {
26+
$rootScope.formSubmission = function(e) {
27+
if (e) {
28+
$rootScope.formSubmitted = 'foo';
29+
}
30+
};
31+
32+
element = $compile('<form action="" ng-submit="formSubmission($event)">' +
33+
'<input type="submit"/>' +
34+
'</form>')($rootScope);
35+
$rootScope.$digest();
36+
expect($rootScope.formSubmitted).not.toBeDefined();
37+
38+
browserTrigger(element.children()[0]);
39+
expect($rootScope.formSubmitted).toEqual('foo');
40+
}));
2441
});
2542
});

0 commit comments

Comments
 (0)