1
votes

I have a simple form which uses knockoutjs and knockoutvalidation. When running IE in comptability mode I have the following behaviour.

A field is required.:

self.oldPassword = ko.observable().extend({ required: true});

When loading the page, I can see in debug mode that the message is: Field is required.

But when I start typing the error changes into: Please enter a value greater than or equal to true.

I am lost here, cause I want to support at least also IE8. I dont have this problem in IE10, Chrome or FireFox. And I dont want to rewrite all my javascript files with the knockout models and validations.

Does this problem sound familiar? And is there a solution?

2

2 Answers

1
votes

Knockout validation checks if html-5 validation attributes have been specified on element your observable binded to and adds equivalent validation rules. This is list of html-5 validation attributes it checks:

var html5Attributes = ['required', 'pattern', 'min', 'max', 'step'];

For each of them it calls hasAttribute function:

hasAttribute: function (node, attr) {
    return node.getAttribute(attr) !== null;
}

In IE7/IE8 compatibility mode node.getAttribute(attr) returns empty string if attribute isn't found so this expression "node.getAttribute(attr) !== null" is always true.

So your observable in compatibility mode will have 5 additional validation rules. Fortunately, all of this is irrelevant for real IE7/IE8

0
votes

i would scan your vm for any instance of a min validation rule and make sure that isn't set to true. that error message is specific for the built in min rule, and if you set the params to true for that rule, it would spit that error message out.

i recreated the problem with the following:

var vm = function () {
    var self = this;

    self.oldPassword = ko.observable().extend({ required: true });

    self.oldPassword.extend({
        min: true
    });
}

if you didnt use the min rule at all, make sure that the knockout validation js file isn't incorrect or something odd.