Permalink
Browse files

validationState always notifies.

* Fixes a problem when an observable has multiple validators and a
different validator fails (the state is still invalid, but the
validation message element should have its content updated).
  • Loading branch information...
1 parent dea3453 commit 9b604c178237831c2a02ed7aeb65e294830b8b49 @luizfar luizfar committed Dec 31, 2013
Showing with 16 additions and 2 deletions.
  1. +11 −1 spec/validation-element-spec.js
  2. +5 −1 src/ko-validation.js
@@ -3,7 +3,7 @@ describe('Validation message element', function () {
beforeEach(function () {
viewModel = {
- firstName: ko.observable('').extend({ 'required': ['First Name'] })
+ firstName: ko.observable('').extend({ 'required': ['First Name'], 'length': ['First Name', 10] })
};
});
@@ -40,6 +40,16 @@ describe('Validation message element', function () {
expect(validationElement).toHaveClass('validation-message');
expect(validationElement).toHaveClass('validation-fixed');
});
+
+ it('updates the element text when the validation message changes but the state does not', function () {
+ var validationElement;
+
+ $('#firstName').val('').trigger('change');
+ $('#firstName').val('Extra Long Name That Should Not Be Valid').trigger('change');
+
+ validationElement = $($('#parent').children()[1]);
+ expect(validationElement.text()).toBe('First Name cannot be longer than 10 characters.');
+ });
});
describe('when a custom validation element is specified', function() {
View
@@ -67,7 +67,11 @@ ko.validation.registerValidator = function (name, validatorFactory) {
if (isFirstValidatorForObservable) {
observable.__validators__ = [];
- observable.validationState = ko.observable(ko.validation.validationStates.PRISTINE);
+ observable.validationState = ko.observable(
+ ko.validation.validationStates.PRISTINE
+ ).extend({
+ 'notify': 'always'
+ });
observable.validationMessage = ko.observable('');
observable.validate = function () {
ko.validation.utils.runValidations(observable);

0 comments on commit 9b604c1

Please sign in to comment.