File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -330,6 +330,14 @@ var formDirectiveFactory = function(isNgForm) {
330
330
331
331
addEventListenerFn ( formElement [ 0 ] , 'submit' , preventDefaultListener ) ;
332
332
333
+ if ( isNgForm && formElement . children ( 'input[type=submit]' ) ) {
334
+ if ( formElement . children ( 'input[type=submit]' ) ) {
335
+ formElement . children ( 'input[type=submit]' ) . on ( 'click' , function ( ) {
336
+ formElement . trigger ( 'submit' ) ;
337
+ } ) ;
338
+ }
339
+ }
340
+
333
341
// unregister the preventDefault listener so that we don't not leak memory but in a
334
342
// way that will achieve the prevention of the default action.
335
343
formElement . on ( '$destroy' , function ( ) {
Original file line number Diff line number Diff line change @@ -148,6 +148,22 @@ describe('form', function() {
148
148
} ) . toThrowMinErr ( 'ng' , 'badname' ) ;
149
149
} ) ;
150
150
151
+ it ( 'should trigger "submit" event for ngForm when clicking inputs with type="submit"' , function ( ) {
152
+ var callback = jasmine . createSpy ( 'submit' ) . andCallFake ( function ( event ) {
153
+ expect ( event . isDefaultPrevented ( ) ) . toBe ( false ) ;
154
+ event . preventDefault ( ) ;
155
+ } ) ;
156
+
157
+ doc = $compile ( '<div ng-form="form">' +
158
+ '<input name="some" ng-model="some" />' +
159
+ '<input type="submit" value="Submit" />' +
160
+ '</div>' ) ( scope ) ;
161
+ doc . on ( 'submit' , callback ) ;
162
+
163
+ browserTrigger ( doc . find ( 'input[type=submit]' ) , 'click' ) ;
164
+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
165
+ } ) ;
166
+
151
167
152
168
describe ( 'preventing default submission' , function ( ) {
153
169
You can’t perform that action at this time.
0 commit comments