Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

validationState always notifies. #33

Merged
merged 1 commit into from

2 participants

@luizfar
  • 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).
@luizfar luizfar 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).
9b604c1
@Jigarsolanki
Collaborator

LGTM

@Jigarsolanki Jigarsolanki merged commit e918679 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 31, 2013
  1. @luizfar

    validationState always notifies.

    luizfar authored
    * 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).
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 2 deletions.
  1. +11 −1 spec/validation-element-spec.js
  2. +5 −1 src/ko-validation.js
View
12 spec/validation-element-spec.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
6 src/ko-validation.js
@@ -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);
Something went wrong with that request. Please try again.