This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -454,7 +454,8 @@ var formDirectiveFactory = function(isNgForm) {
454454
455455 return {
456456 pre : function ngFormPreLink ( scope , formElement , attr , controller ) {
457- if ( ! attr . action ) {
457+ // if `action` attr is not present on the form, prevent the default action (submission)
458+ if ( ! ( 'action' in attr ) ) {
458459 // we can't use jq events because if a form is destroyed during submission the default
459460 // action is not prevented. see #1238
460461 //
Original file line number Diff line number Diff line change @@ -12,10 +12,14 @@ describe('event directives', function() {
1212 describe ( 'ngSubmit' , function ( ) {
1313
1414 it ( 'should get called on form submit' , inject ( function ( $rootScope , $compile ) {
15- element = $compile ( '<form action="" ng-submit="submitted = true">' +
15+ element = $compile ( '<form action="/foo " ng-submit="submitted = true">' +
1616 '<input type="submit"/>' +
1717 '</form>' ) ( $rootScope ) ;
1818 $rootScope . $digest ( ) ;
19+
20+ // prevent submit within the test harness
21+ element . on ( 'submit' , function ( e ) { e . preventDefault ( ) ; } ) ;
22+
1923 expect ( $rootScope . submitted ) . not . toBeDefined ( ) ;
2024
2125 browserTrigger ( element . children ( ) [ 0 ] ) ;
@@ -29,10 +33,14 @@ describe('event directives', function() {
2933 }
3034 } ;
3135
32- element = $compile ( '<form action="" ng-submit="formSubmission($event)">' +
36+ element = $compile ( '<form action="/foo " ng-submit="formSubmission($event)">' +
3337 '<input type="submit"/>' +
3438 '</form>' ) ( $rootScope ) ;
3539 $rootScope . $digest ( ) ;
40+
41+ // prevent submit within the test harness
42+ element . on ( 'submit' , function ( e ) { e . preventDefault ( ) ; } ) ;
43+
3644 expect ( $rootScope . formSubmitted ) . not . toBeDefined ( ) ;
3745
3846 browserTrigger ( element . children ( ) [ 0 ] ) ;
You can’t perform that action at this time.
0 commit comments