From 4806d28a29ae5c3f83d8f97c11e692ca2313c9ab Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 13 Mar 2012 14:56:52 -0700 Subject: fix(forms): remove control.$form and use nullFormCtrl --- src/directive/form.js | 3 ++- src/directive/input.js | 19 ++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/directive/form.js b/src/directive/form.js index a1bfcd12..6bb1b4d6 100644 --- a/src/directive/form.js +++ b/src/directive/form.js @@ -4,7 +4,8 @@ var nullFormCtrl = { $addControl: noop, $removeControl: noop, - $setValidity: noop + $setValidity: noop, + $setDirty: noop } /** diff --git a/src/directive/input.js b/src/directive/input.js index fee7a082..a92ad306 100644 --- a/src/directive/input.js +++ b/src/directive/input.js @@ -742,8 +742,8 @@ var inputDirective = [function() { * @description * */ -var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel', - function($scope, $exceptionHandler, $attr, ngModel) { +var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel', '$element', + function($scope, $exceptionHandler, $attr, ngModel, $element) { this.$viewValue = Number.NaN; this.$modelValue = Number.NaN; this.$parsers = []; @@ -757,6 +757,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel', this.$render = noop; this.$name = $attr.name; + var parentForm = $element.inheritedData('$formController') || nullFormCtrl; /** * @ngdoc function @@ -789,9 +790,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel', this.$valid = false; } - if (this.$form) { - this.$form.$setValidity(validationErrorKey, isValid, this); - } + parentForm.$setValidity(validationErrorKey, isValid, this); }; @@ -819,7 +818,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel', if (this.$pristine) { this.$dirty = true; this.$pristine = false; - if (this.$form) this.$form.$setDirty(); + parentForm.$setDirty(); } forEach(this.$parsers, function(fn) { @@ -907,11 +906,9 @@ var ngModelDirective = [function() { // notify others, especially parent forms var modelCtrl = ctrls[0], - formCtrl = ctrls[1]; - - modelCtrl.$form = formCtrl; + formCtrl = ctrls[1] || nullFormCtrl; - if (formCtrl) formCtrl.$addControl(modelCtrl); + formCtrl.$addControl(modelCtrl); forEach(['valid', 'invalid', 'pristine', 'dirty'], function(name) { scope.$watch(function() { @@ -922,7 +919,7 @@ var ngModelDirective = [function() { }); element.bind('$destroy', function() { - if (formCtrl) formCtrl.$removeControl(modelCtrl); + formCtrl.$removeControl(modelCtrl); }); } }; -- cgit v1.2.3