Kye
Kye

Reputation: 6239

How to explicitly validate a knockoutJs observable

I'm using KnoockoutJS and the validation plugin from here, https://github.com/ericmbarnard/Knockout-Validation.

By default, validation messages only appear after a field has been modified. The problem is that when the user clicks "Save", I need to validate the bound observable regardless of whether the user has modified the field or not.

I can't seem to find a .Validate()on an obervable...

Upvotes: 0

Views: 1900

Answers (2)

Stefan Turcanu
Stefan Turcanu

Reputation: 924

I use ko.validatedObservable($data)().isValid() to get whether the viewmodel is false or not.

If there is somebody who knows a better way, please leave a comment :)

Upvotes: 0

MHollis
MHollis

Reputation: 1459

Looks like ko.validation.validateObservable might be what you're looking for... I didn't test it, but that looks like it.

Upvotes: 3

Related Questions