Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 912 Bytes

README.md

File metadata and controls

32 lines (21 loc) · 912 Bytes

not-valid-knockout

Interface between knockout and not-valid.

Usage

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
);

Testing

If you need to reduce the debounce time for testing you can set the environment variable NOT_VALID_KNOCKOUT_DEBOUNCE.

License

Made with 💖 by NewOrbit in Oxfordshire, and licensed under the MIT License