-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- reorganise project to split out languages
- JS now supports registering events against something other than `document`
- Loading branch information
Showing
72 changed files
with
126 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ | |
/node_modules/ | ||
/yarn.lock | ||
|
||
.yarn/* | ||
!.yarn/releases | ||
!.yarn/plugins | ||
.pnp.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
import './resources_src/index'; | ||
import './resources_src/css/styles' | ||
import './js/src/css/styles.js'; | ||
import {init} from './js/src/index.js'; | ||
|
||
export * from './js/src/index.js'; | ||
|
||
init(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import './base/base.js'; | ||
import './inputs/inputs.js'; | ||
import './errors/errors.js'; | ||
import './button/button.js'; | ||
import './guidance/guidance.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {addErrors, clearErrors, validateForm, validateHandler} from './validation.js'; | ||
|
||
export * from './validation.js'; | ||
|
||
let _init = new WeakSet(); | ||
|
||
export function init(rootElement = document) | ||
{ | ||
if(_init.has(rootElement)) | ||
{ | ||
return; | ||
} | ||
_init.add(rootElement); | ||
|
||
rootElement.addEventListener( | ||
'submit', e => | ||
{ | ||
/** | ||
* @type {HTMLFormElement} | ||
*/ | ||
const form = e.path && e.path[0] || e.target; | ||
const results = validateForm(form); | ||
results.forEach( | ||
(result, handlerName) => | ||
{ | ||
// show errors if necessary | ||
const errContainer = form.querySelector(`.p-form__field[handler-name="${handlerName}"] .p-form__errors`); | ||
if(errContainer) | ||
{ | ||
errContainer.classList.toggle('p-form__errors--hidden', result.errors.length === 0); | ||
} | ||
|
||
if(result.errors.length > 0) | ||
{ | ||
clearErrors(form, handlerName); | ||
addErrors(form, handlerName, result.errors); | ||
e.preventDefault(); | ||
e.stopImmediatePropagation(); | ||
} | ||
}, | ||
); | ||
}, | ||
); | ||
|
||
rootElement.addEventListener( | ||
'reset', e => | ||
{ | ||
/** | ||
* @type {HTMLFormElement} | ||
*/ | ||
const form = e.path && e.path[0] || e.target; | ||
form.querySelectorAll('.p-form__field[handler-name]') | ||
.forEach((ele) => clearErrors(form, ele.getAttribute('handler-name'))); | ||
} | ||
); | ||
|
||
rootElement.addEventListener('input', e => | ||
{ | ||
const inputEle = e.path && e.path[0] || e.target; | ||
const handlerContainer = inputEle.closest('.p-form__field'); | ||
if(!handlerContainer || !handlerContainer.hasAttribute('handler-name')) | ||
{ | ||
return; | ||
} | ||
const handlerName = handlerContainer.getAttribute('handler-name'); | ||
|
||
const form = inputEle.closest('form'); | ||
if(!form) | ||
{ | ||
return; | ||
} | ||
|
||
const result = validateHandler(form, handlerName); | ||
const errContainer = handlerContainer.querySelector(`.p-form__errors`); | ||
if(errContainer && result.errors.length === 0) | ||
{ | ||
clearErrors(form, handlerName); | ||
errContainer.classList.add('p-form__errors--hidden'); | ||
} | ||
else if(!result.potentiallyValid) | ||
{ | ||
clearErrors(form, handlerName); | ||
addErrors(form, handlerName, result.errors); | ||
} | ||
}); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
{ | ||
"name": "@packaged/form", | ||
"version": "3.6.9", | ||
"main": "resources_src/index.js", | ||
"version": "4.0.0", | ||
"main": "/index.js", | ||
"repository": "[email protected]:packaged/form", | ||
"author": "Tom Kay <[email protected]>", | ||
"license": "MIT", | ||
"files": [ | ||
"resources", | ||
"resources_src", | ||
"js", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"@packaged/validate": "^2.7.1", | ||
"base-64": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.11.1", | ||
"@babel/preset-env": "^7.11.0", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-commonjs": "^13.0.0", | ||
"@rollup/plugin-node-resolve": "^8.0.1", | ||
"@babel/core": "^7.15.0", | ||
"@babel/preset-env": "^7.15.0", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^20.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.4", | ||
"core-js": "3", | ||
"postcss": "^8.3.6", | ||
"postcss-preset-env": "^6.7.0", | ||
"rollup": "^2.15.0", | ||
"rollup-plugin-postcss": "^3.1.8", | ||
"rollup-plugin-terser": "^6.1.0" | ||
"rollup": "^2.56.3", | ||
"rollup-plugin-postcss": "^4.0.1", | ||
"rollup-plugin-terser": "^7.0.2" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c rollup.config.js -w" | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters