Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validationState always notifies. #33

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion spec/validation-element-spec.js
Expand Up @@ -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] })
};
});

Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/ko-validation.js
Expand Up @@ -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);
Expand Down