Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit cea7a10

Browse files
committed
1.2.0
1 parent 6fdf355 commit cea7a10

File tree

3 files changed

+77
-44
lines changed

3 files changed

+77
-44
lines changed

dist/validate.js

Lines changed: 74 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-validate
33
* https://github.com/angular-ui/ui-validate
4-
* Version: 1.1.1 - 2015-07-20T03:33:55.729Z
4+
* Version: 1.2.0 - 2015-09-29T04:34:17.056Z
55
* License: MIT
66
*/
77

@@ -14,7 +14,7 @@
1414
* an arbitrary validation function requires creation of custom directives for interact with angular's validation mechanism.
1515
* The ui-validate directive makes it easy to use any function(s) defined in scope as a validator function(s).
1616
* A validator function will trigger validation on both model and input changes.
17-
*
17+
*
1818
* This utility bring 'ui-validate' directives to handle regular validations and 'ui-validate-async' for asynchronous validations.
1919
*
2020
* @example <input ui-validate=" 'myValidatorFunction($value)' ">
@@ -28,17 +28,17 @@
2828
* If an object literal is passed a key denotes a validation error key while a value should be a validator function.
2929
* In both cases validator function should take a value to validate as its argument and should return true/false indicating a validation result.
3030
* It is possible for a validator function to return a promise, however promises are better handled by ui-validate-async.
31-
*
31+
*
3232
* @param ui-validate-async {string|object literal} If strings is passed it should be a scope's function to be used as a validator.
3333
* If an object literal is passed a key denotes a validation error key while a value should be a validator function.
34-
* Async validator function should take a value to validate as its argument and should return a promise that resolves if valid and reject if not,
35-
* indicating a validation result.
34+
* Async validator function should take a value to validate as its argument and should return a promise that resolves if valid and reject if not,
35+
* indicating a validation result.
3636
* ui-validate-async supports non asyncronous validators. They are wrapped into a promise. Although is recomented to use ui-validate instead, since
3737
* all validations declared in ui-validate-async are registered un ngModel.$asyncValidators that runs after ngModel.$validators if and only if
3838
* all validators in ngModel.$validators reports as valid.
3939
*/
4040
angular.module('ui.validate',[])
41-
.directive('uiValidate', ['$$uiValidateApplyWatch', function($$uiValidateApplyWatch) {
41+
.directive('uiValidate', ['$$uiValidateApplyWatch', '$$uiValidateApplyWatchCollection', function ($$uiValidateApplyWatch, $$uiValidateApplyWatchCollection) {
4242

4343
return {
4444
restrict: 'A',
@@ -83,12 +83,15 @@ angular.module('ui.validate',[])
8383

8484
// Support for ui-validate-watch
8585
if (attrs.uiValidateWatch) {
86-
$$uiValidateApplyWatch(scope, ctrl, scope.$eval(attrs.uiValidateWatch));
86+
$$uiValidateApplyWatch(scope, ctrl, scope.$eval(attrs.uiValidateWatch), attrs.uiValidateWatchObjectEquality);
87+
}
88+
if (attrs.uiValidateWatchCollection) {
89+
$$uiValidateApplyWatchCollection(scope, ctrl, scope.$eval(attrs.uiValidateWatchCollection));
8790
}
8891
}
8992
};
9093
}])
91-
.directive('uiValidateAsync', ['$$uiValidateApplyWatch', '$timeout', '$q', function ($$uiValidateApplyWatch, $timeout, $q) {
94+
.directive('uiValidateAsync', ['$$uiValidateApplyWatch', '$$uiValidateApplyWatchCollection', '$timeout', '$q', function ($$uiValidateApplyWatch, $$uiValidateApplyWatchCollection, $timeout, $q) {
9295

9396
return {
9497
restrict: 'A',
@@ -132,45 +135,75 @@ angular.module('ui.validate',[])
132135

133136
// Support for ui-validate-watch
134137
if (attrs.uiValidateWatch){
135-
$$uiValidateApplyWatch( scope, ctrl, scope.$eval(attrs.uiValidateWatch) );
138+
$$uiValidateApplyWatch( scope, ctrl, scope.$eval(attrs.uiValidateWatch), attrs.uiValidateWatchObjectEquality);
139+
}
140+
if (attrs.uiValidateWatchCollection) {
141+
$$uiValidateApplyWatchCollection(scope, ctrl, scope.$eval(attrs.uiValidateWatchCollection));
136142
}
137143
}
138144
};
139145
}])
140-
.service('$$uiValidateApplyWatch', function() {
141-
return function(scope, ctrl, watch) {
142-
143-
//string - update all validators on expression change
144-
if (angular.isString(watch)) {
145-
scope.$watch(watch, function() {
146+
.service('$$uiValidateApplyWatch', function () {
147+
return function (scope, ctrl, watch, objectEquality) {
148+
var watchCallback = function () {
146149
ctrl.$validate();
147-
});
148-
//array - update all validators on change of any expression
149-
} else if (angular.isArray(watch)) {
150-
angular.forEach(watch, function(expression) {
151-
scope.$watch(expression, function() {
152-
ctrl.$validate();
150+
};
151+
152+
//string - update all validators on expression change
153+
if (angular.isString(watch)) {
154+
scope.$watch(watch, watchCallback, objectEquality);
155+
//array - update all validators on change of any expression
156+
} else if (angular.isArray(watch)) {
157+
angular.forEach(watch, function (expression) {
158+
scope.$watch(expression, watchCallback, objectEquality);
153159
});
154-
});
155-
//object - update appropriate validator
156-
} else if (angular.isObject(watch)) {
157-
angular.forEach(watch, function(expression/*, validatorKey*/) {
158-
//value is string - look after one expression
159-
if (angular.isString(expression)) {
160-
scope.$watch(expression, function() {
161-
ctrl.$validate();
162-
});
163-
}
164-
//value is array - look after all expressions in array
165-
if (angular.isArray(expression)) {
166-
angular.forEach(expression, function(intExpression) {
167-
scope.$watch(intExpression, function() {
168-
ctrl.$validate();
160+
//object - update appropriate validator
161+
} else if (angular.isObject(watch)) {
162+
angular.forEach(watch, function (expression/*, validatorKey*/) {
163+
//value is string - look after one expression
164+
if (angular.isString(expression)) {
165+
scope.$watch(expression, watchCallback, objectEquality);
166+
}
167+
//value is array - look after all expressions in array
168+
if (angular.isArray(expression)) {
169+
angular.forEach(expression, function (intExpression) {
170+
scope.$watch(intExpression, watchCallback, objectEquality);
169171
});
170-
});
171-
}
172-
});
173-
}};
174-
});
172+
}
173+
});
174+
}
175+
};
176+
})
177+
.service('$$uiValidateApplyWatchCollection', function () {
178+
return function (scope, ctrl, watch) {
179+
var watchCallback = function () {
180+
ctrl.$validate();
181+
};
182+
183+
//string - update all validators on expression change
184+
if (angular.isString(watch)) {
185+
scope.$watchCollection(watch, watchCallback);
186+
//array - update all validators on change of any expression
187+
} else if (angular.isArray(watch)) {
188+
angular.forEach(watch, function (expression) {
189+
scope.$watchCollection(expression, watchCallback);
190+
});
191+
//object - update appropriate validator
192+
} else if (angular.isObject(watch)) {
193+
angular.forEach(watch, function (expression/*, validatorKey*/) {
194+
//value is string - look after one expression
195+
if (angular.isString(expression)) {
196+
scope.$watchCollection(expression, watchCallback);
197+
}
198+
//value is array - look after all expressions in array
199+
if (angular.isArray(expression)) {
200+
angular.forEach(expression, function (intExpression) {
201+
scope.$watchCollection(intExpression, watchCallback);
202+
});
203+
}
204+
});
205+
}
206+
};
207+
});
175208

176209
}());

dist/validate.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-validate",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"author": "https://github.com/angular-ui/ui-validate/graphs/contributors",
55
"license": "MIT",
66
"homepage": "https://github.com/angular-ui/ui-validate",

0 commit comments

Comments
 (0)