using isValid() with HTML5 validation attributes
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
Do you have the "parseInputAttributes" option set to true on for your validation options?
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.
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.