Skip to content

Commit

Permalink
Added extender to trigger validation on another observable.
Browse files Browse the repository at this point in the history
  • Loading branch information
moyesm committed Jun 11, 2015
1 parent e9b8f0e commit 52fa96a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/general-validation-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ define(['knockout'], function(ko) {
},
message: 'The field must not equal {0}'
};

// technically not a validation rule, this extender simply triggers validation
// on another observable. Useful for validating a range of dates, for example,
// where a change to startDate could cause endDate's dateIsAfter rule to be validated.
ko.extenders.triggerValidationOn = function(target, dependency) {
target.subscribe(function() {
// force knockout validation to rerun validation on dependency
ko.validation.validateObservable(dependency);
// update UI (validate() is defined in validation-utilities.js)
dependency.validate();
});
return target;
};
});

0 comments on commit 52fa96a

Please sign in to comment.