I wrote validation expression that depends on more than one element of scope (other than $value that is validated).
Currently ui-validate-watch supports revalidation only when one scope member changed.
To support ui-validate-watch looking after any count of expressions I re-wrote part responsible for ui-validate-watch.
After that fix following constructions allowed:
ui-validate-watch="['expression1', 'expression2', ...]" - all validators will be re-validated if any of expressions changes.
ui-validate-watch="{is_my_check_passed: ['expression1', 'expression2', ...]}" - validator with key 'is_my_check_passed' will be re-validated if any of expressions changes.
All old variants work as well.
Below is code for that fix:
// Support for ui-validate-watch
if (attrs.uiValidateWatch){
apply_watch( scope.$eval(attrs.uiValidateWatch) );
}
function apply_watch(watch)
{
//string - update all validators on expression change
if (angular.isString(watch))
{
scope.$watch(watch, function(){
angular.forEach(validators, function(validatorFn){
validatorFn(ctrl.$modelValue);
});
});
return;
}
//array - update all validators on change of any expression
if (angular.isArray(watch))
{
angular.forEach(watch, function(expression){
scope.$watch(expression, function()
{
angular.forEach(validators, function(validatorFn){
validatorFn(ctrl.$modelValue);
});
});
});
return;
}
//object - update appropriate validator
if (angular.isObject(watch))
{
angular.forEach(watch, function(expression, validatorKey)
{
//value is string - look after one expression
if (angular.isString(expression))
{
scope.$watch(expression, function(){
validators[validatorKey](ctrl.$modelValue);
});
}
//value is array - look after all expressions in array
if (angular.isArray(expression))
{
angular.forEach(expression, function(intExpression)
{
scope.$watch(intExpression, function(){
validators[validatorKey](ctrl.$modelValue);
});
});
}
});
}
}
Sorry, I have not time to create normal pull request.