Unable to configure knockout verification

I am trying to set up a knockout check, but my settings seem to be ignored. This is how I try to configure it

var knockoutValidationSettings = {
    insertMessages: true,
    decorateElement: true,
    errorMessageClass: 'error',
    errorElementClass: 'error',
    errorClass: 'error',
    errorsAsTitle: true,
    parseInputAttributes: false,
    messagesOnModified: true,
    decorateElementOnModified: true,
    decorateInputElement: true
};
ko.validation.init(knockoutValidationSettings);

ko.applyBindings(vm, $('#dropzone')[0]);

I know the options object is not a problem because it works fine

var knockoutValidationSettings = {
    insertMessages: true,
    decorateElement: true,
    errorMessageClass: 'error',
    errorElementClass: 'error',
    errorClass: 'error',
    errorsAsTitle: true,
    parseInputAttributes: false,
    messagesOnModified: true,
    decorateElementOnModified: true,
    decorateInputElement: true
};
//ko.validation.init(knockoutValidationSettings);

ko.applyBindingsWithValidation(vm, $('#dropzone')[0], knockoutValidationSettings);

How can I make the init function work? Obviously, I would like to move this initialization to one place in the root of my application.

+4
source share
2 answers

It seems that the validation plugin was already initialized at the time of the call ko.validation.init.

So, you need to pass trueas the second argument to force the initialization to use the new configuration:

ko.validation.init(knockoutValidationSettings, true);

?

  • ko.applyBindings ko.applyBindingsWithValidation
  • ko.validation.init ko.validation.configure

ko.applyBindingsWithValidation , - - .

+14

- . , errorMessageClass "field-validation-valid-ui, ".

, "field-validation-valid " ( ASP.NET MVC ClientSide/jQuery) - , , .

0

Source: https://habr.com/ru/post/1524770/


All Articles