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

Commit 7787d00

Browse files
committed
fixup! use a different way of setting submitted
1 parent 4f94819 commit 7787d00

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/ng/directive/form.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var nullFormCtrl = {
99
$setValidity: noop,
1010
$setDirty: noop,
1111
$setPristine: noop,
12-
$setSubmitted: noop
12+
$setSubmitted: noop,
13+
$$setSubmitted: noop
1314
},
1415
PENDING_CLASS = 'ng-pending',
1516
SUBMITTED_CLASS = 'ng-submitted';
@@ -277,17 +278,20 @@ FormController.prototype = {
277278
* Sets the form to its `$submitted` state. This will also set `$submitted` on all child and
278279
* parent forms of the form.
279280
*/
280-
$setSubmitted: function(onlySetOnChildren) {
281-
this.$$animate.addClass(this.$$element, SUBMITTED_CLASS);
282-
this.$submitted = true;
283-
284-
if (!onlySetOnChildren) {
285-
this.$$parentForm.$setSubmitted();
281+
$setSubmitted: function() {
282+
var rootForm = this;
283+
while (rootForm.$$parentForm && (rootForm.$$parentForm !== nullFormCtrl)) {
284+
rootForm = rootForm.$$parentForm;
286285
}
286+
rootForm.$$setSubmitted();
287+
},
287288

289+
$$setSubmitted: function() {
290+
this.$$animate.addClass(this.$$element, SUBMITTED_CLASS);
291+
this.$submitted = true;
288292
forEach(this.$$controls, function(control) {
289-
if (control.$setSubmitted && !control.$submitted) {
290-
control.$setSubmitted(true);
293+
if (control.$$setSubmitted && !control.$submitted) {
294+
control.$$setSubmitted();
291295
}
292296
});
293297
}

test/ng/directive/formSpec.js

-8
Original file line numberDiff line numberDiff line change
@@ -573,19 +573,11 @@ describe('form', function() {
573573
child = scope.child,
574574
grandchild = scope.grandchild;
575575

576-
spyOn(parent, '$setSubmitted').and.callThrough();
577-
spyOn(child, '$setSubmitted').and.callThrough();
578-
spyOn(grandchild, '$setSubmitted').and.callThrough();
579-
580576
child.$setSubmitted();
581577

582578
expect(parent.$submitted).toBeTruthy();
583579
expect(child.$submitted).toBeTruthy();
584580
expect(grandchild.$submitted).toBeTruthy();
585-
586-
expect(parent.$setSubmitted).toHaveBeenCalledOnce();
587-
expect(child.$setSubmitted).toHaveBeenCalledOnce();
588-
expect(grandchild.$setSubmitted).toHaveBeenCalledOnce();
589581
});
590582

591583
it('should deregister a child form when its DOM is removed', function() {

0 commit comments

Comments
 (0)