1.0.2 • Published 6 years ago
valli v1.0.2
Valli
Valli is an unobtrusive validator. It's designed on the basis of event-driven architecture with the help of HTML5.
Installation
yarn add valli
# or "npm i valli"
Usage
<form>
<input type="email" required>
<input type="text" pattern="^\w+$">
<button>submit</button>
</form>
import { Valli } from 'Valli';
const form = document.querySelector('form');
const controls = Array.from(document.querySelectorAll('input'));
const button = document.querySelector('button');
const valli = new Valli({ form, controls });
form.addEventListener('valli', ev => {
const { el, valid } = ev.detail;
el.style.background = valid ? '' : '#fcc';
button.disabled = !valli.valid;
}, false);