Search code examples
knockout.jsknockout-validation

Showing validation messages just after binding with Knockout Validation


With Knockout Validation it appears that validation is performed only when a key is hit on a control which might change an observable value.

When I bind the first time, the validation is not performed (messages are not shown if the initial values are invalid). I just need to focus on one of my input controls and write a letter and unfocus it so that validation is performed.

How can I show all the messages around each control recursively just after the first binding? I tried the group solution , but I have a nested hierarchy of validatedObservable this produces a maxStackSize exceeded


Solution

  • You can configure knockout.validation to show the messages immediately.

    ko.validation.init({ messagesOnModified: false });
    

    Details about the configuration can be found at the following wiki page: https://github.com/ericmbarnard/Knockout-Validation/wiki/Configuration