npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

html5-form-validator

1.0.0 • Public • Published

GitHub release GitHub issues GitHub last commit Github file size Build Status npm npm Analytics

HTML5 Form Validator

The simplest HTML5 forms validator

Install

npm i html5-form-validator

or

yarn add html5-form-validator

or

Just download this repository and link the files located in dist folder.

Usage

import 'html5-form-validator';

Then initialize with default settings:

new html5formValidation();

or supply your own

const form = document.querySelector('#form');
 
new html5formValidation(form, {
    errorElement: 'form__error',
    invalidClass: 'is--invalid',
    submitHandler(instance) {
        console.log(instance);
    },
    validateOnInput: false
});

Options

errorElement - The classname of the element that will be added to the dom after the required field. Defaults to error.

invalidClass - The classname of the required field when it is invalid. Defaults to invalid.

submitHandler - A function to run on valid form submission. Accepts a single instance argument which refers to the constuctor's instance. Defaults to null.

validateOnInput - Set to false if you want to show visual feedback for invalid fields after the first invalid submission. Defaults to true.

LICENSE

MIT

install

npm i html5-form-validator

Downloadsweekly downloads

9

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability