1.1.5 • Published 2 years ago

nwhval v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

NWH Validator - Frontend validation done right.

This library is a fully working and up to date (Bootstrap 5+) validator for any HTML form.

Installation

NPM

npm install nwhval

YARN

yarn add nwhval

Usage

import Validator from "nwhval";

const form = document.querySelector("#my-form");
const validator = new Validator(form);

form.addEventListener("submit", (e) => {
  e.preventDefault();

  if (validator.validate()) {
    // form is valid, get ready for backend validation !
  }
});

Configuration

You can pass parameters to the validator constructor to configure it.

ParameterDescriptionDefault valueAvailable Options
stylingWether to use Bootstrap 4 or 5 stylingbootstrap-5boostrap-4, bootstrap-5
classToClass to add to the form-groupform-group
errorClassClass to add to the form-group when the field is invalidis-invalid
successClassClass to add to the form-group when the field is validis-valid
errorTextParentParent element to add the error textform-group
errorTextTagTag to use to add the error textdiv
errorTextClassClass to add to the error textinvalid-feedback
liveWhether to validate the form on keyup or on submittrue
langLanguage to use for the error messagesenfr, es, en

A note on the lang parameter

Currently, only English, French and Spanish are supported. Feel free to add your own language and open a merge request !

Config Usage

import Validator from "nwhval";

const validatorConfig = {
  styling: "bootstrap-5",
  classTo: "form-group",
  errorClass: "is-invalid",
  successClass: "is-valid",
  errorTextParent: "form-group",
  errorTextClass: "invalid-feedback",
  errorTextTag: "div",
  live: true,
  lang: "en",
};

const form = document.querySelector("#my-form");
const validator = new Validator(form, validatorConfig);

form.addEventListener("submit", (e) => {
  e.preventDefault();

  if (validator.validate()) {
    // form is valid, get ready for backend validation !
  }
});
1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago