html5-form-validator
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -1,199 +0,123 @@ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(); | ||
else if(typeof define === 'function' && define.amd) | ||
define([], factory); | ||
else if(typeof exports === 'object') | ||
exports["html5formValidation"] = factory(); | ||
else | ||
root["html5formValidation"] = factory(); | ||
})(window, function() { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { | ||
/******/ configurable: false, | ||
/******/ enumerable: true, | ||
/******/ get: getter | ||
/******/ }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 0); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.index = mod.exports; | ||
} | ||
})(this, function (_exports) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports.default = void 0; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
var html5formValidation = | ||
/*#__PURE__*/ | ||
function () { | ||
function html5formValidation() { | ||
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.querySelector('form'); | ||
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
_classCallCheck(this, html5formValidation); | ||
var html5formValidation = | ||
/*#__PURE__*/ | ||
function () { | ||
function html5formValidation() { | ||
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.querySelector('form'); | ||
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
this.settings = Object.assign({}, { | ||
errorElement: 'error', | ||
invalidClass: 'invalid', | ||
submitHandler: null, | ||
validateOnInput: true | ||
}, settings); | ||
this.form = element; | ||
this.errorDiv = "<div class=\"".concat(this.settings.errorElement, "\"></div>"); | ||
this.init(); | ||
} | ||
_classCallCheck(this, html5formValidation); | ||
_createClass(html5formValidation, [{ | ||
key: "init", | ||
value: function init() { | ||
var _this = this; | ||
this.settings = Object.assign({}, { | ||
errorElement: 'error', | ||
invalidClass: 'invalid', | ||
submitHandler: null, | ||
validateOnInput: true | ||
}, settings); | ||
this.form = element; | ||
this.errorDiv = "<div class=\"".concat(this.settings.errorElement, "\"></div>"); | ||
this.init(); | ||
} | ||
this.form.noValidate = true; | ||
this.settings.validateOnInput && this.validateAll(this.form); | ||
_createClass(html5formValidation, [{ | ||
key: "init", | ||
value: function init() { | ||
var _this = this; | ||
this.form.onsubmit = function (event) { | ||
_this.validateAll(_this.form); | ||
this.form.noValidate = true; | ||
this.settings.validateOnInput && this.validateAll(this.form); | ||
this.form.onsubmit = function (event) { | ||
_this.validateAll(_this.form); | ||
if (!_this.form.checkValidity()) { | ||
event.preventDefault(); | ||
} else { | ||
if (typeof _this.settings.submitHandler === 'function') { | ||
if (!_this.form.checkValidity()) { | ||
event.preventDefault(); | ||
} else { | ||
if (typeof _this.settings.submitHandler === 'function') { | ||
event.preventDefault(); | ||
_this.settings.submitHandler(_this); | ||
_this.settings.submitHandler(_this); | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
}, { | ||
key: "validateAll", | ||
value: function validateAll(form) { | ||
var requiredFields = form.querySelectorAll('[required]'); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
}; | ||
} | ||
}, { | ||
key: "validateAll", | ||
value: function validateAll(form) { | ||
var requiredFields = form.querySelectorAll('[required]'); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = requiredFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var field = _step.value; | ||
this.validateField(field); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
for (var _iterator = requiredFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var field = _step.value; | ||
this.validateField(field); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: "validateField", | ||
value: function validateField(field) { | ||
var _this2 = this; | ||
}, { | ||
key: "validateField", | ||
value: function validateField(field) { | ||
var _this2 = this; | ||
if (!(field.nextSibling.classList && field.nextSibling.classList.contains(this.settings.errorElement))) { | ||
field.insertAdjacentHTML('afterend', this.errorDiv); | ||
} | ||
if (!(field.nextSibling.classList && field.nextSibling.classList.contains(this.settings.errorElement))) { | ||
field.insertAdjacentHTML('afterend', this.errorDiv); | ||
} | ||
field.oninvalid = function () { | ||
field.classList.add(_this2.settings.invalidClass); | ||
field.nextSibling.textContent = field.validationMessage; | ||
}; | ||
field.oninvalid = function () { | ||
field.classList.add(_this2.settings.invalidClass); | ||
field.nextSibling.textContent = field.validationMessage; | ||
}; | ||
field.oninput = function () { | ||
field.nextSibling.textContent = ''; | ||
field.classList.remove(_this2.settings.invalidClass); | ||
field.checkValidity(); | ||
}; | ||
} | ||
}]); | ||
field.oninput = function () { | ||
field.nextSibling.textContent = ''; | ||
field.classList.remove(_this2.settings.invalidClass); | ||
field.checkValidity(); | ||
}; | ||
} | ||
}]); | ||
return html5formValidation; | ||
}(); | ||
return html5formValidation; | ||
}(); | ||
exports.default = html5formValidation; | ||
/***/ }) | ||
/******/ ])["default"]; | ||
}); | ||
_exports.default = html5formValidation; | ||
}); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.html5formValidation=e():t.html5formValidation=e()}(window,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.querySelector("form"),n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.settings=Object.assign({},{errorElement:"error",invalidClass:"invalid",submitHandler:null,validateOnInput:!0},n),this.form=e,this.errorDiv='<div class="'.concat(this.settings.errorElement,'"></div>'),this.init()}var e,n,r;return e=t,(n=[{key:"init",value:function(){var t=this;this.form.noValidate=!0,this.settings.validateOnInput&&this.validateAll(this.form),this.form.onsubmit=function(e){t.validateAll(t.form),t.form.checkValidity()?"function"==typeof t.settings.submitHandler&&(e.preventDefault(),t.settings.submitHandler(t)):e.preventDefault()}}},{key:"validateAll",value:function(t){var e=t.querySelectorAll("[required]"),n=!0,i=!1,r=void 0;try{for(var o,a=e[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var l=o.value;this.validateField(l)}}catch(t){i=!0,r=t}finally{try{n||null==a.return||a.return()}finally{if(i)throw r}}}},{key:"validateField",value:function(t){var e=this;t.nextSibling.classList&&t.nextSibling.classList.contains(this.settings.errorElement)||t.insertAdjacentHTML("afterend",this.errorDiv),t.oninvalid=function(){t.classList.add(e.settings.invalidClass),t.nextSibling.textContent=t.validationMessage},t.oninput=function(){t.nextSibling.textContent="",t.classList.remove(e.settings.invalidClass),t.checkValidity()}}}])&&i(e.prototype,n),r&&i(e,r),t}();e.default=r}]).default}); | ||
(function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(exports);else{var c={exports:{}};b(c.exports),a.index=c.exports}})(this,function(a){"use strict";function b(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function c(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function d(a,b,d){return b&&c(a.prototype,b),d&&c(a,d),a}Object.defineProperty(a,"__esModule",{value:!0}),a.default=void 0;var e=function(){function a(){var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.querySelector("form"),d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};b(this,a),this.settings=Object.assign({},{errorElement:"error",invalidClass:"invalid",submitHandler:null,validateOnInput:!0},d),this.form=c,this.errorDiv="<div class=\"".concat(this.settings.errorElement,"\"></div>"),this.init()}return d(a,[{key:"init",value:function b(){var a=this;this.form.noValidate=!0,this.settings.validateOnInput&&this.validateAll(this.form),this.form.onsubmit=function(b){a.validateAll(a.form),a.form.checkValidity()?"function"==typeof a.settings.submitHandler&&(b.preventDefault(),a.settings.submitHandler(a)):b.preventDefault()}}},{key:"validateAll",value:function i(a){var b=a.querySelectorAll("[required]"),c=!0,d=!1,e=void 0;try{for(var f,g,h=b[Symbol.iterator]();!(c=(f=h.next()).done);c=!0)g=f.value,this.validateField(g)}catch(a){d=!0,e=a}finally{try{c||null==h.return||h.return()}finally{if(d)throw e}}}},{key:"validateField",value:function c(a){var b=this;a.nextSibling.classList&&a.nextSibling.classList.contains(this.settings.errorElement)||a.insertAdjacentHTML("afterend",this.errorDiv),a.oninvalid=function(){a.classList.add(b.settings.invalidClass),a.nextSibling.textContent=a.validationMessage},a.oninput=function(){a.nextSibling.textContent="",a.classList.remove(b.settings.invalidClass),a.checkValidity()}}}]),a}();a.default=e}); |
{ | ||
"name": "html5-form-validator", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "The most simple HTML5 form validator", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "webpack" | ||
"dist": "babel src/index.js --out-file dist/index.js", | ||
"minify": "babel src/index.js --out-file dist/index.min.js --presets minify,@babel/env", | ||
"build": "npm run dist && npm run minify" | ||
}, | ||
@@ -18,3 +20,3 @@ "repository": { | ||
], | ||
"author": "Atanas Atanasov <scriptex.bg@gmail.com> (https://github.com/scriptex)", | ||
"author": "Atanas Atanasov <scriptex.bg@gmail.com> (https://atanas.info)", | ||
"license": "MIT", | ||
@@ -26,11 +28,18 @@ "bugs": { | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.44", | ||
"@babel/core": "^7.0.0-beta.44", | ||
"@babel/preset-env": "^7.0.0-beta.44", | ||
"@babel/preset-stage-2": "^7.0.0-beta.44", | ||
"babel-loader": "^8.0.0-beta", | ||
"unminified-webpack-plugin": "^2.0.0", | ||
"webpack": "^4.5.0", | ||
"webpack-cli": "^2.0.14" | ||
"@babel/cli": "^7.0.0-beta.51", | ||
"@babel/core": "^7.0.0-beta.51", | ||
"@babel/plugin-proposal-class-properties": "7.0.0-beta.54", | ||
"@babel/plugin-proposal-decorators": "7.0.0-beta.54", | ||
"@babel/plugin-proposal-export-namespace-from": "7.0.0-beta.54", | ||
"@babel/plugin-proposal-function-sent": "7.0.0-beta.54", | ||
"@babel/plugin-proposal-json-strings": "7.0.0-beta.54", | ||
"@babel/plugin-proposal-numeric-separator": "7.0.0-beta.54", | ||
"@babel/plugin-proposal-throw-expressions": "7.0.0-beta.54", | ||
"@babel/plugin-syntax-dynamic-import": "7.0.0-beta.54", | ||
"@babel/plugin-syntax-import-meta": "7.0.0-beta.54", | ||
"@babel/plugin-transform-modules-umd": "^7.0.0-rc.1", | ||
"@babel/preset-env": "^7.0.0-beta.51", | ||
"babel-loader": "^8.0.0-beta.0", | ||
"babel-minify": "^0.4.3" | ||
} | ||
} |
@@ -0,8 +1,18 @@ | ||
[![GitHub release](https://img.shields.io/github/release/scriptex/html5-form-validator.svg)](https://github.com/scriptex/html5-form-validator/releases/latest) | ||
[![GitHub issues](https://img.shields.io/github/issues/scriptex/html5-form-validator.svg)](https://github.com/scriptex/html5-form-validator/issues) | ||
[![GitHub last commit](https://img.shields.io/github/last-commit/scriptex/html5-form-validator.svg)](https://github.com/scriptex/html5-form-validator/commits/master) | ||
[![Github file size](https://img.shields.io/github/size/scriptex/html5-form-validator/dist/index.min.js.svg)](https://github.com/scriptex/html5-form-validator) | ||
[![Build Status](https://travis-ci.org/scriptex/html5-form-validator.svg?branch=master)](https://travis-ci.org/scriptex/html5-form-validator) | ||
[![npm](https://img.shields.io/npm/dt/html5-form-validator.svg)](https://www.npmjs.com/package/html5-form-validator) | ||
[![npm](https://img.shields.io/npm/v/html5-form-validator.svg)](https://www.npmjs.com/package/html5-form-validator) | ||
[![Analytics](https://ga-beacon.appspot.com/UA-83446952-1/github.com/scriptex/html5-form-validator/README.md)](https://github.com/scriptex/html5-form-validator/) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/scriptex/html5-form-validator.svg)](https://greenkeeper.io/) | ||
# HTML5 Form Validator | ||
The most simple HTML5 forms validator | ||
The simplest HTML5 forms validator | ||
## Install | ||
``` | ||
```console | ||
npm i html5-form-validator | ||
@@ -13,3 +23,3 @@ ``` | ||
``` | ||
```console | ||
yarn add html5-form-validator | ||
@@ -20,11 +30,7 @@ ``` | ||
Just download this repository and link the files located in dist folder: | ||
Just download this repository and link the files located in dist folder. | ||
``` | ||
<script src="dist/index.min.js"></script> | ||
``` | ||
## Usage | ||
``` | ||
```javascript | ||
import 'html5-form-validator'; | ||
@@ -35,3 +41,3 @@ ``` | ||
``` | ||
```javascript | ||
new html5formValidation(); | ||
@@ -42,12 +48,12 @@ ``` | ||
``` | ||
```javascript | ||
const form = document.querySelector('#form'); | ||
new html5formValidation(form, { | ||
errorElement: 'form__error', | ||
invalidClass: 'is--invalid', | ||
submitHandler(instance) { | ||
console.log(instance) | ||
}, | ||
validateOnInput: false | ||
errorElement: 'form__error', | ||
invalidClass: 'is--invalid', | ||
submitHandler(instance) { | ||
console.log(instance); | ||
}, | ||
validateOnInput: false | ||
}); | ||
@@ -65,1 +71,5 @@ ``` | ||
`validateOnInput` - Set to false if you want to show visual feedback for invalid fields after the first invalid submission. Defaults to `true`. | ||
## LICENSE | ||
MIT |
Sorry, the diff of this file is not supported yet
71
14113
15
8
171