Interface between not-valid and knockout
npm install not-valid-knockouttypescript
import { createValidator } from "not-valid";
import { createKnockoutWrapper } from "not-valid-knockout";
const mustBeJames = createValidator(v => v === "James", "Value must be 'James'");
const name = ko.observable();
const nameErrors = ko.observableArray();
const bindValidation = createKnockoutWrapper().bindValidation;
// subscribe to an observable, validate, put errors into an observableArray
bindValidation(
[ mustBeJames ],
name,
nameErrors
);
`
Testing
If you need to reduce the debounce time for testing you can set the environment variable NOT_VALID_KNOCKOUT_DEBOUNCE`.