Knockout-Validation icon indicating copy to clipboard operation
Knockout-Validation copied to clipboard

using isValid() with HTML5 validation attributes

Open findorf opened this issue 14 years ago • 3 comments

if I have Using JS and observable().extend() I can use the isValid() function:

var myValue = ko.observable().extend({ required: true });
console.log('before', myValue.isValid())
myValue('hello world');
console.log('after', myValue.isValid())

but if I try the same with my HTML5 required attribute:

<input type="email" value="" size="25" id="UserEmail" required data-bind="{value : Preferences.Email}" maxlength="64" />
SITE.Address.FirstName.isValid() // SITE.Address is my viewmodel

isValid is not a function. How can I achieve this?

findorf avatar Aug 21 '12 12:08 findorf

@findorf

Do you have the "parseInputAttributes" option set to true on for your validation options?

ericmbarnard avatar Aug 27 '12 00:08 ericmbarnard

I'm having the same issue. If I extend the observable I am able to see the isValid() function but just setting the HTML5 required option I don't see the isValid() on the observable. Am I doing something wrong? I have tried setting the parseInputAttributes: true in the configuration but it's still not working.

jbrnrdn avatar Feb 08 '13 22:02 jbrnrdn

I figured this out. The issue was that I was displaying the the errors from a ko.computed array. But the computed was not getting triggered unless I referenced isValid() of the entire viewmodel.

jbrnrdn avatar Feb 11 '13 14:02 jbrnrdn