This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +12
-3
lines changed
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) {
454
454
455
455
return {
456
456
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 ) ) {
458
459
// we can't use jq events because if a form is destroyed during submission the default
459
460
// action is not prevented. see #1238
460
461
//
Original file line number Diff line number Diff line change @@ -12,10 +12,14 @@ describe('event directives', function() {
12
12
describe ( 'ngSubmit' , function ( ) {
13
13
14
14
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">' +
16
16
'<input type="submit"/>' +
17
17
'</form>' ) ( $rootScope ) ;
18
18
$rootScope . $digest ( ) ;
19
+
20
+ // prevent submit within the test harness
21
+ element . on ( 'submit' , function ( e ) { e . preventDefault ( ) ; } ) ;
22
+
19
23
expect ( $rootScope . submitted ) . not . toBeDefined ( ) ;
20
24
21
25
browserTrigger ( element . children ( ) [ 0 ] ) ;
@@ -29,10 +33,14 @@ describe('event directives', function() {
29
33
}
30
34
} ;
31
35
32
- element = $compile ( '<form action="" ng-submit="formSubmission($event)">' +
36
+ element = $compile ( '<form action="/foo " ng-submit="formSubmission($event)">' +
33
37
'<input type="submit"/>' +
34
38
'</form>' ) ( $rootScope ) ;
35
39
$rootScope . $digest ( ) ;
40
+
41
+ // prevent submit within the test harness
42
+ element . on ( 'submit' , function ( e ) { e . preventDefault ( ) ; } ) ;
43
+
36
44
expect ( $rootScope . formSubmitted ) . not . toBeDefined ( ) ;
37
45
38
46
browserTrigger ( element . children ( ) [ 0 ] ) ;
You can’t perform that action at this time.
0 commit comments