Interface between knockout and not-valid.
import { createValidator } from "not-valid";
import { createKnockoutWrapper } from "not-valid-knockout";
const mustBeJames = createValidator<string>(v => v === "James", "Value must be 'James'");
const name = ko.observable<string>();
const nameErrors = ko.observableArray<string>();
const bindValidation = createKnockoutWrapper().bindValidation;
// subscribe to an observable, validate, put errors into an observableArray
bindValidation<string>(
[ mustBeJames ],
name,
nameErrors
);
If you need to reduce the debounce time for testing you can set the environment variable NOT_VALID_KNOCKOUT_DEBOUNCE
.
Made with 💖 by NewOrbit in Oxfordshire, and licensed under the MIT License