From f59e4b11f11261c234a821db67088f0de88a2852 Mon Sep 17 00:00:00 2001
From: Igor Minar
Date: Mon, 12 Mar 2012 21:12:15 -0700
Subject: fix(forms): prefix all form and control properties with $
---
src/directive/form.js | 60 ++++-----
src/directive/input.js | 332 ++++++++++++++++++++++++------------------------
src/directive/select.js | 26 ++--
3 files changed, 209 insertions(+), 209 deletions(-)
(limited to 'src')
diff --git a/src/directive/form.js b/src/directive/form.js
index 27ba1044..5427384a 100644
--- a/src/directive/form.js
+++ b/src/directive/form.js
@@ -5,12 +5,12 @@
* @ngdoc object
* @name angular.module.ng.$compileProvider.directive.form.FormController
*
- * @property {boolean} pristine True if user has not interacted with the form yet.
- * @property {boolean} dirty True if user has already interacted with the form.
- * @property {boolean} valid True if all of the containg widgets are valid.
- * @property {boolean} invalid True if at least one containing widget is invalid.
+ * @property {boolean} $pristine True if user has not interacted with the form yet.
+ * @property {boolean} $dirty True if user has already interacted with the form.
+ * @property {boolean} $valid True if all of the containg widgets are valid.
+ * @property {boolean} $invalid True if at least one containing widget is invalid.
*
- * @property {Object} error Is an object hash, containing references to all invalid widgets, where
+ * @property {Object} $error Is an object hash, containing references to all invalid widgets, where
*
* - keys are error ids (such as `REQUIRED`, `URL` or `EMAIL`),
* - values are arrays of widgets that are invalid with given error.
@@ -22,11 +22,11 @@
* of `FormController`.
*
*/
-FormController.$inject = ['$scope', 'name', '$element'];
-function FormController($scope, name, element) {
+FormController.$inject = ['name', '$element'];
+function FormController(name, element) {
var form = this,
parentForm = element.parent().inheritedData('$formController'),
- errors = form.error = {};
+ errors = form.$error = {};
// publish the form into scope
name(this);
@@ -36,14 +36,14 @@ function FormController($scope, name, element) {
}
form.$addControl = function(control) {
- if (control.name && !form.hasOwnProperty(control.name)) {
- form[control.name] = control;
+ if (control.$name && !form.hasOwnProperty(control.$name)) {
+ form[control.$name] = control;
}
}
form.$removeControl = function(control) {
- if (control.name && form[control.name] === control) {
- delete form[control.name];
+ if (control.$name && form[control.$name] === control) {
+ delete form[control.$name];
}
forEach(errors, cleanupControlErrors, control);
};
@@ -53,27 +53,27 @@ function FormController($scope, name, element) {
cleanupControlErrors(errors[validationToken], validationToken, control);
if (equals(errors, {})) {
- form.valid = true;
- form.invalid = false;
+ form.$valid = true;
+ form.$invalid = false;
}
} else {
addControlError(validationToken, control);
- form.valid = false;
- form.invalid = true;
+ form.$valid = false;
+ form.$invalid = true;
}
};
form.$setDirty = function() {
- form.dirty = true;
- form.pristine = false;
+ form.$dirty = true;
+ form.$pristine = false;
}
// init state
- form.dirty = false;
- form.pristine = true;
- form.valid = true;
- form.invalid = false;
+ form.$dirty = false;
+ form.$pristine = true;
+ form.$valid = true;
+ form.$invalid = false;
function cleanupControlErrors(queue, validationToken, control) {
if (queue) {
@@ -180,24 +180,24 @@ function FormController($scope, name, element) {
it('should initialize to model', function() {
expect(binding('userType')).toEqual('guest');
- expect(binding('myForm.input.valid')).toEqual('true');
+ expect(binding('myForm.input.$valid')).toEqual('true');
});
it('should be invalid if empty', function() {
input('userType').enter('');
expect(binding('userType')).toEqual('');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
@@ -219,7 +219,7 @@ var formDirective = [function() {
forEach(['valid', 'invalid', 'dirty', 'pristine'], function(name) {
scope.$watch(function() {
- return controller[name];
+ return controller['$' + name];
}, function(value) {
formElement[value ? 'addClass' : 'removeClass']('ng-' + name);
});
diff --git a/src/directive/input.js b/src/directive/input.js
index 019bfaf0..6295a4b0 100644
--- a/src/directive/input.js
+++ b/src/directive/input.js
@@ -38,33 +38,33 @@ var inputType = {
it('should initialize to model', function() {
expect(binding('text')).toEqual('guest');
- expect(binding('myForm.input.valid')).toEqual('true');
+ expect(binding('myForm.input.$valid')).toEqual('true');
});
it('should be invalid if empty', function() {
input('text').enter('');
expect(binding('text')).toEqual('');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
it('should be invalid if multi word', function() {
input('text').enter('hello world');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
@@ -106,33 +106,33 @@ var inputType = {
it('should initialize to model', function() {
expect(binding('value')).toEqual('12');
- expect(binding('myForm.input.valid')).toEqual('true');
+ expect(binding('myForm.input.$valid')).toEqual('true');
});
it('should be invalid if empty', function() {
input('value').enter('');
expect(binding('value')).toEqual('');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
it('should be invalid if over max', function() {
input('value').enter('123');
expect(binding('value')).toEqual('');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
@@ -171,33 +171,33 @@ var inputType = {
it('should initialize to model', function() {
expect(binding('text')).toEqual('http://google.com');
- expect(binding('myForm.input.valid')).toEqual('true');
+ expect(binding('myForm.input.$valid')).toEqual('true');
});
it('should be invalid if empty', function() {
input('text').enter('');
expect(binding('text')).toEqual('');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
it('should be invalid if not url', function() {
input('text').enter('xxx');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
@@ -234,33 +234,33 @@ var inputType = {
it('should initialize to model', function() {
expect(binding('text')).toEqual('me@example.com');
- expect(binding('myForm.input.valid')).toEqual('true');
+ expect(binding('myForm.input.$valid')).toEqual('true');
});
it('should be invalid if empty', function() {
input('text').enter('');
expect(binding('text')).toEqual('');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
it('should be invalid if not email', function() {
input('text').enter('xxx');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.input.$valid')).toEqual('false');
});
@@ -370,12 +370,12 @@ function isEmpty(value) {
function textInputType(scope, element, attr, ctrl) {
element.bind('blur', function() {
scope.$apply(function() {
- ctrl.setViewValue(trim(element.val()));
+ ctrl.$setViewValue(trim(element.val()));
});
});
- ctrl.render = function() {
- element.val(isEmpty(ctrl.viewValue) ? '' : ctrl.viewValue);
+ ctrl.$render = function() {
+ element.val(isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue);
};
// pattern validator
@@ -384,10 +384,10 @@ function textInputType(scope, element, attr, ctrl) {
var validate = function(regexp, value) {
if (isEmpty(value) || regexp.test(value)) {
- ctrl.setValidity('PATTERN', true);
+ ctrl.$setValidity('PATTERN', true);
return value;
} else {
- ctrl.setValidity('PATTERN', false);
+ ctrl.$setValidity('PATTERN', false);
return undefined;
}
};
@@ -409,8 +409,8 @@ function textInputType(scope, element, attr, ctrl) {
};
}
- ctrl.formatters.push(patternValidator);
- ctrl.parsers.push(patternValidator);
+ ctrl.$formatters.push(patternValidator);
+ ctrl.$parsers.push(patternValidator);
}
// min length validator
@@ -418,16 +418,16 @@ function textInputType(scope, element, attr, ctrl) {
var minlength = parseInt(attr.ngMinlength, 10);
var minLengthValidator = function(value) {
if (!isEmpty(value) && value.length < minlength) {
- ctrl.setValidity('MINLENGTH', false);
+ ctrl.$setValidity('MINLENGTH', false);
return undefined;
} else {
- ctrl.setValidity('MINLENGTH', true);
+ ctrl.$setValidity('MINLENGTH', true);
return value;
}
};
- ctrl.parsers.push(minLengthValidator);
- ctrl.formatters.push(minLengthValidator);
+ ctrl.$parsers.push(minLengthValidator);
+ ctrl.$formatters.push(minLengthValidator);
}
// max length validator
@@ -435,34 +435,34 @@ function textInputType(scope, element, attr, ctrl) {
var maxlength = parseInt(attr.ngMaxlength, 10);
var maxLengthValidator = function(value) {
if (!isEmpty(value) && value.length > maxlength) {
- ctrl.setValidity('MAXLENGTH', false);
+ ctrl.$setValidity('MAXLENGTH', false);
return undefined;
} else {
- ctrl.setValidity('MAXLENGTH', true);
+ ctrl.$setValidity('MAXLENGTH', true);
return value;
}
};
- ctrl.parsers.push(maxLengthValidator);
- ctrl.formatters.push(maxLengthValidator);
+ ctrl.$parsers.push(maxLengthValidator);
+ ctrl.$formatters.push(maxLengthValidator);
}
};
function numberInputType(scope, element, attr, ctrl) {
textInputType(scope, element, attr, ctrl);
- ctrl.parsers.push(function(value) {
+ ctrl.$parsers.push(function(value) {
var empty = isEmpty(value);
if (empty || NUMBER_REGEXP.test(value)) {
- ctrl.setValidity('NUMBER', true);
+ ctrl.$setValidity('NUMBER', true);
return value === '' ? null : (empty ? value : parseFloat(value));
} else {
- ctrl.setValidity('NUMBER', false);
+ ctrl.$setValidity('NUMBER', false);
return undefined;
}
});
- ctrl.formatters.push(function(value) {
+ ctrl.$formatters.push(function(value) {
return isEmpty(value) ? '' : '' + value;
});
@@ -470,41 +470,41 @@ function numberInputType(scope, element, attr, ctrl) {
var min = parseFloat(attr.min);
var minValidator = function(value) {
if (!isEmpty(value) && value < min) {
- ctrl.setValidity('MIN', false);
+ ctrl.$setValidity('MIN', false);
return undefined;
} else {
- ctrl.setValidity('MIN', true);
+ ctrl.$setValidity('MIN', true);
return value;
}
};
- ctrl.parsers.push(minValidator);
- ctrl.formatters.push(minValidator);
+ ctrl.$parsers.push(minValidator);
+ ctrl.$formatters.push(minValidator);
}
if (attr.max) {
var max = parseFloat(attr.max);
var maxValidator = function(value) {
if (!isEmpty(value) && value > max) {
- ctrl.setValidity('MAX', false);
+ ctrl.$setValidity('MAX', false);
return undefined;
} else {
- ctrl.setValidity('MAX', true);
+ ctrl.$setValidity('MAX', true);
return value;
}
};
- ctrl.parsers.push(maxValidator);
- ctrl.formatters.push(maxValidator);
+ ctrl.$parsers.push(maxValidator);
+ ctrl.$formatters.push(maxValidator);
}
- ctrl.formatters.push(function(value) {
+ ctrl.$formatters.push(function(value) {
if (isEmpty(value) || isNumber(value)) {
- ctrl.setValidity('NUMBER', true);
+ ctrl.$setValidity('NUMBER', true);
return value;
} else {
- ctrl.setValidity('NUMBER', false);
+ ctrl.$setValidity('NUMBER', false);
return undefined;
}
});
@@ -515,16 +515,16 @@ function urlInputType(scope, element, attr, ctrl) {
var urlValidator = function(value) {
if (isEmpty(value) || URL_REGEXP.test(value)) {
- ctrl.setValidity('URL', true);
+ ctrl.$setValidity('URL', true);
return value;
} else {
- ctrl.setValidity('URL', false);
+ ctrl.$setValidity('URL', false);
return undefined;
}
};
- ctrl.formatters.push(urlValidator);
- ctrl.parsers.push(urlValidator);
+ ctrl.$formatters.push(urlValidator);
+ ctrl.$parsers.push(urlValidator);
}
function emailInputType(scope, element, attr, ctrl) {
@@ -532,16 +532,16 @@ function emailInputType(scope, element, attr, ctrl) {
var emailValidator = function(value) {
if (isEmpty(value) || EMAIL_REGEXP.test(value)) {
- ctrl.setValidity('EMAIL', true);
+ ctrl.$setValidity('EMAIL', true);
return value;
} else {
- ctrl.setValidity('EMAIL', false);
+ ctrl.$setValidity('EMAIL', false);
return undefined;
}
};
- ctrl.formatters.push(emailValidator);
- ctrl.parsers.push(emailValidator);
+ ctrl.$formatters.push(emailValidator);
+ ctrl.$parsers.push(emailValidator);
}
function radioInputType(scope, element, attr, ctrl) {
@@ -551,14 +551,14 @@ function radioInputType(scope, element, attr, ctrl) {
element.bind('click', function() {
if (element[0].checked) {
scope.$apply(function() {
- ctrl.setViewValue(attr.value);
+ ctrl.$setViewValue(attr.value);
});
};
});
- ctrl.render = function() {
+ ctrl.$render = function() {
var value = attr.value;
- element[0].checked = isDefined(value) && (value == ctrl.viewValue);
+ element[0].checked = isDefined(value) && (value == ctrl.$viewValue);
};
}
@@ -571,19 +571,19 @@ function checkboxInputType(scope, element, attr, ctrl) {
element.bind('click', function() {
scope.$apply(function() {
- ctrl.setViewValue(element[0].checked);
+ ctrl.$setViewValue(element[0].checked);
});
});
- ctrl.render = function() {
- element[0].checked = ctrl.viewValue;
+ ctrl.$render = function() {
+ element[0].checked = ctrl.$viewValue;
};
- ctrl.formatters.push(function(value) {
+ ctrl.$formatters.push(function(value) {
return value === trueValue;
});
- ctrl.parsers.push(function(value) {
+ ctrl.$parsers.push(function(value) {
return value ? trueValue : falseValue;
});
}
@@ -646,63 +646,63 @@ function checkboxInputType(scope, element, attr, ctrl) {
user = {{user}}
- myForm.userName.valid = {{myForm.userName.valid}}
- myForm.userName.error = {{myForm.userName.error}}
- myForm.lastName.valid = {{myForm.lastName.valid}}
- myForm.userName.error = {{myForm.lastName.error}}
- myForm.valid = {{myForm.valid}}
- myForm.error.REQUIRED = {{!!myForm.error.REQUIRED}}
- myForm.error.MINLENGTH = {{!!myForm.error.MINLENGTH}}
- myForm.error.MAXLENGTH = {{!!myForm.error.MAXLENGTH}}
+ myForm.userName.$valid = {{myForm.userName.$valid}}
+ myForm.userName.$error = {{myForm.userName.$error}}
+ myForm.lastName.$valid = {{myForm.lastName.$valid}}
+ myForm.userName.$error = {{myForm.lastName.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.REQUIRED = {{!!myForm.$error.REQUIRED}}
+ myForm.$error.MINLENGTH = {{!!myForm.$error.MINLENGTH}}
+ myForm.$error.MAXLENGTH = {{!!myForm.$error.MAXLENGTH}}
it('should initialize to model', function() {
expect(binding('user')).toEqual('{"last":"visitor","name":"guest"}');
- expect(binding('myForm.userName.valid')).toEqual('true');
- expect(binding('myForm.valid')).toEqual('true');
+ expect(binding('myForm.userName.$valid')).toEqual('true');
+ expect(binding('myForm.$valid')).toEqual('true');
});
it('should be invalid if empty when required', function() {
input('user.name').enter('');
expect(binding('user')).toEqual('{"last":"visitor"}');
- expect(binding('myForm.userName.valid')).toEqual('false');
- expect(binding('myForm.valid')).toEqual('false');
+ expect(binding('myForm.userName.$valid')).toEqual('false');
+ expect(binding('myForm.$valid')).toEqual('false');
});
it('should be valid if empty when min length is set', function() {
input('user.last').enter('');
expect(binding('user')).toEqual('{"last":"","name":"guest"}');
- expect(binding('myForm.lastName.valid')).toEqual('true');
- expect(binding('myForm.valid')).toEqual('true');
+ expect(binding('myForm.lastName.$valid')).toEqual('true');
+ expect(binding('myForm.$valid')).toEqual('true');
});
it('should be invalid if less than required min length', function() {
input('user.last').enter('xx');
expect(binding('user')).toEqual('{"name":"guest"}');
- expect(binding('myForm.lastName.valid')).toEqual('false');
- expect(binding('myForm.lastName.error')).toMatch(/MINLENGTH/);
- expect(binding('myForm.valid')).toEqual('false');
+ expect(binding('myForm.lastName.$valid')).toEqual('false');
+ expect(binding('myForm.lastName.$error')).toMatch(/MINLENGTH/);
+ expect(binding('myForm.$valid')).toEqual('false');
});
it('should be invalid if longer than max length', function() {
input('user.last').enter('some ridiculously long name');
expect(binding('user'))
.toEqual('{"name":"guest"}');
- expect(binding('myForm.lastName.valid')).toEqual('false');
- expect(binding('myForm.lastName.error')).toMatch(/MAXLENGTH/);
- expect(binding('myForm.valid')).toEqual('false');
+ expect(binding('myForm.lastName.$valid')).toEqual('false');
+ expect(binding('myForm.lastName.$error')).toMatch(/MAXLENGTH/);
+ expect(binding('myForm.$valid')).toEqual('false');
});
@@ -729,7 +729,7 @@ var inputDirective = [function() {
* @property {Array.} parsers Whenever the widget reads value from the DOM, it executes
* all of these functions to sanitize / convert the value as well as validate.
*
- * @property {Array.} formatters Wheneveer the model value changes, it executes all of
+ * @property {Array.} formatters Whenever the model value changes, it executes all of
* these functions to convert the value as well as validate.
*
* @property {Object} error An bject hash with all errors as keys.
@@ -744,23 +744,23 @@ var inputDirective = [function() {
*/
var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel',
function($scope, $exceptionHandler, $attr, ngModel) {
- this.viewValue = Number.NaN;
- this.modelValue = Number.NaN;
- this.parsers = [];
- this.formatters = [];
- this.viewChangeListeners = [];
- this.error = {};
- this.pristine = true;
- this.dirty = false;
- this.valid = true;
- this.invalid = false;
- this.render = noop;
- this.name = $attr.name;
+ this.$viewValue = Number.NaN;
+ this.$modelValue = Number.NaN;
+ this.$parsers = [];
+ this.$formatters = [];
+ this.$viewChangeListeners = [];
+ this.$error = {};
+ this.$pristine = true;
+ this.$dirty = false;
+ this.$valid = true;
+ this.$invalid = false;
+ this.$render = noop;
+ this.$name = $attr.name;
/**
* @ngdoc function
- * @name angular.module.ng.$compileProvider.directive.ng-model.NgModelController#setValidity
+ * @name angular.module.ng.$compileProvider.directive.ng-model.NgModelController#$setValidity
* @methodOf angular.module.ng.$compileProvider.directive.ng-model.NgModelController
*
* @description
@@ -772,21 +772,21 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel',
* @param {string} validationToken Name of the validator.
* @param {boolean} isValid Whether the current state is valid (true) or invalid (false).
*/
- this.setValidity = function(validationToken, isValid) {
+ this.$setValidity = function(validationToken, isValid) {
- if (!isValid && this.error[validationToken]) return;
- if (isValid && !this.error[validationToken]) return;
+ if (!isValid && this.$error[validationToken]) return;
+ if (isValid && !this.$error[validationToken]) return;
if (isValid) {
- delete this.error[validationToken];
- if (equals(this.error, {})) {
- this.valid = true;
- this.invalid = false;
+ delete this.$error[validationToken];
+ if (equals(this.$error, {})) {
+ this.$valid = true;
+ this.$invalid = false;
}
} else {
- this.error[validationToken] = true;
- this.invalid = true;
- this.valid = false;
+ this.$error[validationToken] = true;
+ this.$invalid = true;
+ this.$valid = false;
}
if (this.$form) {
@@ -797,7 +797,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel',
/**
* @ngdoc function
- * @name angular.module.ng.$compileProvider.directive.ng-model.NgModelController#setViewValue
+ * @name angular.module.ng.$compileProvider.directive.ng-model.NgModelController#$setViewValue
* @methodOf angular.module.ng.$compileProvider.directive.ng-model.NgModelController
*
* @description
@@ -812,24 +812,24 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel',
*
* @param {string} value Value from the view.
*/
- this.setViewValue = function(value) {
- this.viewValue = value;
+ this.$setViewValue = function(value) {
+ this.$viewValue = value;
// change to dirty
- if (this.pristine) {
- this.dirty = true;
- this.pristine = false;
+ if (this.$pristine) {
+ this.$dirty = true;
+ this.$pristine = false;
if (this.$form) this.$form.$setDirty();
}
- forEach(this.parsers, function(fn) {
+ forEach(this.$parsers, function(fn) {
value = fn(value);
});
- if (this.modelValue !== value) {
- this.modelValue = value;
+ if (this.$modelValue !== value) {
+ this.$modelValue = value;
ngModel(value);
- forEach(this.viewChangeListeners, function(listener) {
+ forEach(this.$viewChangeListeners, function(listener) {
try {
listener();
} catch(e) {
@@ -846,19 +846,19 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel',
}, function(value) {
// ignore change from view
- if (ctrl.modelValue === value) return;
+ if (ctrl.$modelValue === value) return;
- var formatters = ctrl.formatters,
+ var formatters = ctrl.$formatters,
idx = formatters.length;
- ctrl.modelValue = value;
+ ctrl.$modelValue = value;
while(idx--) {
value = formatters[idx](value);
}
- if (ctrl.viewValue !== value) {
- ctrl.viewValue = value;
- ctrl.render();
+ if (ctrl.$viewValue !== value) {
+ ctrl.$viewValue = value;
+ ctrl.$render();
}
});
}];
@@ -915,7 +915,7 @@ var ngModelDirective = [function() {
forEach(['valid', 'invalid', 'pristine', 'dirty'], function(name) {
scope.$watch(function() {
- return modelCtrl[name];
+ return modelCtrl['$' + name];
}, function(value) {
element[value ? 'addClass' : 'removeClass']('ng-' + name);
});
@@ -980,7 +980,7 @@ var ngModelDirective = [function() {
var ngChangeDirective = valueFn({
require: 'ngModel',
link: function(scope, element, attr, ctrl) {
- ctrl.viewChangeListeners.push(function() {
+ ctrl.$viewChangeListeners.push(function() {
scope.$eval(attr.ngChange);
});
}
@@ -1025,7 +1025,7 @@ var ngModelInstantDirective = ['$browser', function($browser) {
link: function(scope, element, attr, ctrl) {
var handler = function() {
scope.$apply(function() {
- ctrl.setViewValue(trim(element.val()));
+ ctrl.$setViewValue(trim(element.val()));
});
};
@@ -1058,19 +1058,19 @@ var requiredDirective = [function() {
var validator = function(value) {
if (attr.required && (isEmpty(value) || value === false)) {
- ctrl.setValidity('REQUIRED', false);
+ ctrl.$setValidity('REQUIRED', false);
return;
} else {
- ctrl.setValidity('REQUIRED', true);
+ ctrl.$setValidity('REQUIRED', true);
return value;
}
};
- ctrl.formatters.push(validator);
- ctrl.parsers.unshift(validator);
+ ctrl.$formatters.push(validator);
+ ctrl.$parsers.unshift(validator);
attr.$observe('required', function() {
- validator(ctrl.viewValue);
+ validator(ctrl.$viewValue);
});
}
};
@@ -1095,26 +1095,26 @@ var requiredDirective = [function() {
}
it('should initialize to model', function() {
expect(binding('names')).toEqual('["igor","misko","vojta"]');
- expect(binding('myForm.input.valid')).toEqual('true');
+ expect(binding('myForm.namesInput.$valid')).toEqual('true');
});
it('should be invalid if empty', function() {
input('names').enter('');
expect(binding('names')).toEqual('[]');
- expect(binding('myForm.input.valid')).toEqual('false');
+ expect(binding('myForm.namesInput.$valid')).toEqual('false');
});
@@ -1135,9 +1135,9 @@ var ngListDirective = function() {
return list;
};
- ctrl.parsers.push(parse);
- ctrl.formatters.push(function(value) {
- if (isArray(value) && !equals(parse(ctrl.viewValue), value)) {
+ ctrl.$parsers.push(parse);
+ ctrl.$formatters.push(function(value) {
+ if (isArray(value) && !equals(parse(ctrl.$viewValue), value)) {
return value.join(', ');
}
diff --git a/src/directive/select.js b/src/directive/select.js
index e5d619b9..2c6ef15b 100644
--- a/src/directive/select.js
+++ b/src/directive/select.js
@@ -140,15 +140,15 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
// required validator
if (multiple && (attr.required || attr.ngRequired)) {
var requiredValidator = function(value) {
- ctrl.setValidity('REQUIRED', !attr.required || (value && value.length));
+ ctrl.$setValidity('REQUIRED', !attr.required || (value && value.length));
return value;
};
- ctrl.parsers.push(requiredValidator);
- ctrl.formatters.unshift(requiredValidator);
+ ctrl.$parsers.push(requiredValidator);
+ ctrl.$formatters.unshift(requiredValidator);
attr.$observe('required', function() {
- requiredValidator(ctrl.viewValue);
+ requiredValidator(ctrl.$viewValue);
});
}
@@ -162,20 +162,20 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
function Single(scope, selectElement, ctrl) {
- ctrl.render = function() {
- selectElement.val(ctrl.viewValue);
+ ctrl.$render = function() {
+ selectElement.val(ctrl.$viewValue);
};
selectElement.bind('change', function() {
scope.$apply(function() {
- ctrl.setViewValue(selectElement.val());
+ ctrl.$setViewValue(selectElement.val());
});
});
}
function Multiple(scope, selectElement, ctrl) {
- ctrl.render = function() {
- var items = new HashMap(ctrl.viewValue);
+ ctrl.$render = function() {
+ var items = new HashMap(ctrl.$viewValue);
forEach(selectElement.children(), function(option) {
option.selected = isDefined(items.get(option.value));
});
@@ -189,7 +189,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
array.push(option.value);
}
});
- ctrl.setViewValue(array);
+ ctrl.$setViewValue(array);
});
});
}
@@ -266,11 +266,11 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
value = valueFn(scope, locals);
}
}
- ctrl.setViewValue(value);
+ ctrl.$setViewValue(value);
});
});
- ctrl.render = render;
+ ctrl.$render = render;
// TODO(vojta): can't we optimize this ?
scope.$watch(render);
@@ -282,7 +282,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
optionGroup,
option,
existingParent, existingOptions, existingOption,
- modelValue = ctrl.modelValue,
+ modelValue = ctrl.$modelValue,
values = valuesFn(scope) || [],
keys = keyName ? sortedKeys(values) : values,
groupLength, length,
--
cgit v1.2.3