django-forms-frontend-validation 1.0.6__py3-none-any.whl → 1.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django-forms-frontend-validation
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Summary: A Django app for front-end form validation
5
5
  Home-page: https://github.com/andrew-kyle92/django-forms-frontend-validation
6
6
  Author: Andrew Kyle
@@ -36,7 +36,7 @@ The application is designed to streamline the process of form validation, ensuri
36
36
  ## Usage
37
37
  ### Installation
38
38
  1. Install the Django project
39
- ```cmd
39
+ ```bash
40
40
  pip install django-frontend-forms-validation
41
41
  ```
42
42
  ### Setting Up
@@ -52,15 +52,17 @@ The application is designed to streamline the process of form validation, ensuri
52
52
  ```python
53
53
  from formvalidator.settings import *
54
54
 
55
- IGNORED_CLASSES = ['example-class', 'example-class-2', ...]
56
- IGNORE_VALIDATION = ['example-ignore-validation', ...]
55
+ IGNORED_CLASSES = ['example-class', 'example-class-2', ...] # replace these classes with your own
56
+ IGNORE_VALIDATION = ['example-ignore-validation', ...] # replace these classes with your own
57
57
  VALIDATE_ONLY_ON_SUBMIT = ['all'] # Options: "__all__", specific class names, or leave empty.
58
+ # validate only on submit will only validate the inputs when the submit button is clicked
59
+ # leaving it the list blank will allow for validation to happen on focus-out/onblur of an input
58
60
  ```
59
61
  2. Initial Forms:
60
62
  - Ensure the `_InitializeForms` method is called during page load to attach validation logic to forms dynamically.
61
63
  To your HTML template with the form, add this.
62
64
  ```html
63
- <script src="{% static 'dist/forms.bundle.js' %}"></script>
65
+ <script src="{% static 'formsvalidator/js/forms.bundle.js' %}"></script>
64
66
  <script>
65
67
  // fv (formsvalidator) is exported from forms.bundle.js
66
68
  window.addEventListener("load", () => {
@@ -76,6 +78,11 @@ The application is designed to streamline the process of form validation, ensuri
76
78
  });
77
79
  </script>
78
80
  ```
81
+ **Quick Note* - if your template is not finding `'formvalidator/js/forms.bundle.js'`, make sure either `STATICFILES_DIRS` is defined within your settings.py files, or if on production `STATIC_ROOT` is defined. If `STATIC_ROOT` is defined then make sure to run:
82
+ ```bash
83
+ ./manage.py collectstatic
84
+ ```
85
+
79
86
  3. Server-Side Context:
80
87
  - Use the `FormsValidator` class to pass configuration to templates:
81
88
  ```python
@@ -10,19 +10,13 @@ formvalidator/views.py,sha256=TYqBRjnpKccQZA-Dwajp0heJ7-rhEkHetkGqSd12cJs,1391
10
10
  formvalidator/form_utils/__init__.py,sha256=joyuThQtBJ08qadN5rntReKcCRWsonBgy95qKkuaW2E,40
11
11
  formvalidator/form_utils/form_utils.py,sha256=3LzlfAhgd7jkw9KKKJ1YsrTiJgRVKZwIlqgA3A6p-10,698
12
12
  formvalidator/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- formvalidator/static/dist/forms.bundle.js,sha256=duXcJCPOSg7U8RcO82rUBd6JSHf8UKQENWRYBKP3BlA,34808
14
- formvalidator/static/webpack/package-lock.json,sha256=2efugRXwEqLTV-MIyRezE4XfoldXBPjxEdZcZj0cpH8,111553
15
- formvalidator/static/webpack/package.json,sha256=KdvnQsQ2L1D6j7fMzXAAup7TbZAWQqXgQ-jTJKvkNfM,382
16
- formvalidator/static/webpack/webpack.config.js,sha256=1VNt5YvappvIfng4QH6SYpGPsYbGirO4Yu4sTiqpagA,543
17
- formvalidator/static/webpack/src/css/style.css,sha256=k0nLJjqK63fGlhalKs_-RKgsu9szFIzygvIis4hQTVg,536
18
- formvalidator/static/webpack/src/js/formFunctions.js,sha256=SRCfCnENiCSQmoXPGPclIYBsItcQP6qvVPy5w1lCS_E,9095
19
- formvalidator/static/webpack/src/js/index.js,sha256=RZ2f421UJuRHoO9kXQ5RDLfb4EYjebnHEvLxOFfKhJk,53
13
+ formvalidator/static/formvalidator/js/forms.bundle.js,sha256=5gxqawxTVkRroNH-vWyl5KCinFxhFd19H_noaW6wPZQ,34782
20
14
  formvalidator/templates/base.html,sha256=husejzZpyn7DKk-3S6frsalTMz4-ZO5EV5GWobWWEvc,888
21
15
  formvalidator/templates/formvalidator/sample.html,sha256=IKklx25wt-paXmfaMbSZfTZaWFzlq_BGMOuVKACNpyI,2048
22
16
  formvalidator/templates/formvalidator/sample2.html,sha256=_E5Rtv4fWOut5dbpRsguoEUw-X_Hln6wok4g2KPlzCo,2129
23
17
  formvalidator/templates/includes/header.html,sha256=5EWbHxj-JFu7fzmGUWWqOxoG2bwl03UwwUG_O68qzj0,946
24
- django_forms_frontend_validation-1.0.6.dist-info/LICENSE,sha256=gA3cqug2Eqh9zkbcEDQ1Ez1APddDnmbX6bO6_wcBRM8,1095
25
- django_forms_frontend_validation-1.0.6.dist-info/METADATA,sha256=Wiaj50uTgNWofLUcRKc6i_VE-SoTi4Cht6pi7k2Bjug,5091
26
- django_forms_frontend_validation-1.0.6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
27
- django_forms_frontend_validation-1.0.6.dist-info/top_level.txt,sha256=E9SLf9Mg8MAqnCin_sgh__XTquz_st_-Qyy9w3-3fms,14
28
- django_forms_frontend_validation-1.0.6.dist-info/RECORD,,
18
+ django_forms_frontend_validation-1.0.8.dist-info/LICENSE,sha256=gA3cqug2Eqh9zkbcEDQ1Ez1APddDnmbX6bO6_wcBRM8,1095
19
+ django_forms_frontend_validation-1.0.8.dist-info/METADATA,sha256=iWqvkqqxJJnhht6-oUpVfqbd1MydjBxXMdWDEyhaKkI,5692
20
+ django_forms_frontend_validation-1.0.8.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
+ django_forms_frontend_validation-1.0.8.dist-info/top_level.txt,sha256=E9SLf9Mg8MAqnCin_sgh__XTquz_st_-Qyy9w3-3fms,14
22
+ django_forms_frontend_validation-1.0.8.dist-info/RECORD,,
@@ -126,7 +126,7 @@ eval("\n\n/* istanbul ignore next */\nfunction styleTagTransform(css, styleElem
126
126
  \*********************************/
127
127
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
128
128
 
129
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ _Initialize: () => (/* binding */ _Initialize),\n/* harmony export */ _InitializeForms: () => (/* binding */ _InitializeForms),\n/* harmony export */ checkForm: () => (/* binding */ checkForm),\n/* harmony export */ csrftoken: () => (/* binding */ csrftoken),\n/* harmony export */ fetchHandleForm: () => (/* binding */ fetchHandleForm)\n/* harmony export */ });\n// ########## Getting the csrf token for the fetch calls ##########\r\nfunction getCookie(name) {\r\n let cookieValue = null;\r\n if (document.cookie && document.cookie !== '') {\r\n const cookies = document.cookie.split(';');\r\n for (let i = 0; i < cookies.length; i++) {\r\n const cookie = cookies[i].trim();\r\n // Does this cookie string begin with the name we want?\r\n if (cookie.substring(0, name.length + 1) === (name + '=')) {\r\n cookieValue = decodeURIComponent(cookie.substring(name.length + 1));\r\n break;\r\n }\r\n }\r\n }\r\n return cookieValue;\r\n}\r\nconst csrftoken = getCookie('csrftoken');\r\n\r\n// ##### Fetch Calls #####\r\n// performs fetch call to view\r\nconst fetchHandleForm = async (form) => {\r\n let formData = new FormData(form);\r\n return await fetch(form.action, {\r\n method: \"POST\",\r\n credentials: \"same-origin\",\r\n headers: {\r\n // \"Accept\": \"m\",\r\n // \"X-Requested-With\": \"XMLHttpRequest\",\r\n \"X-CSRFToken\": csrftoken,\r\n },\r\n body: formData,\r\n }).then(async (response) => {\r\n return response.json();\r\n });\r\n}\r\n// ***** Adding asterisks to labels of required inputs *****\r\nfunction addAsterisks(form) {\r\n // gathering all inputs\r\n let formGroups = document.querySelectorAll(`#${form.id} .form-group`);\r\n let inputs = getRequiredFields(formGroups);\r\n\r\n // adding the required-field class which will add the asterisk\r\n for (let i = 0; i < inputs.length; i++) {\r\n let label = document.querySelector(`label[for=${inputs[i].name}]`);\r\n if (inputs[i].required) {\r\n label.classList.add(\"required-field\");\r\n }\r\n }\r\n}\r\n\r\n// In-line validation on required fields\r\nfunction validateInputs(form) {\r\n // gathering all inputs\r\n let formGroups = document.querySelectorAll(`#${form.id} .form-group`);\r\n let inputs = getRequiredFields(formGroups);\r\n\r\n // adding listeners to each input for validation\r\n for (let i = 0; i < inputs.length; i++) {\r\n inputs[i].addEventListener(\"focusout\", () => {\r\n if (inputs[i].value === \"\" || inputs[i].value === null) {\r\n addError(inputs[i]);\r\n } else {\r\n removeError(inputs[i]);\r\n }\r\n });\r\n }\r\n}\r\n// validateInputs();\r\n\r\n// check form function\r\nfunction checkForm(form) {\r\n let errors = false;\r\n\r\n // gathering all inputs\r\n let formGroups = document.querySelectorAll(`#${form.id} .form-group`);\r\n let inputs = getRequiredFields(formGroups);\r\n\r\n // iterating through all required fields to check for invalidation\r\n for (let i = 0; i < inputs.length; i++) {\r\n let input = inputs[i];\r\n if (input.value === \"\" || !input.value) {\r\n addError(input);\r\n errors = true;\r\n }\r\n }\r\n\r\n return errors\r\n}\r\n\r\n// submit button validation check\r\nfunction submitValidation(form) {\r\n form.form.addEventListener(\"submit\", (e) => {\r\n // preventing default submission behavior\r\n e.preventDefault();\r\n\r\n // gathering all inputs\r\n let f = e.target;\r\n // let formGroups = document.querySelectorAll(`#${form.id} .form-group`);\r\n // let inputs = getRequiredFields(formGroups);\r\n // // let form = document.getElementById(\"form\") !== null ? document.getElementById(\"form\") : document.getElementById(\"userForm\");\r\n let errors = checkForm(f);\r\n\r\n // submitting the form if there aren't any errors\r\n if (!errors) {\r\n form.form.submit();\r\n } else {\r\n let invalidInputs = document.getElementsByClassName(\"validation-error\");\r\n // scroll to the first invalid input\r\n invalidInputs[0].parentElement.scrollIntoView();\r\n }\r\n });\r\n}\r\n// submitValidation();\r\n\r\n// adds an error to an input\r\nfunction addError(input) {\r\n let inputParent = input.parentElement;\r\n if (!inputParent.className.includes(\"form-group\")){\r\n inputParent = input.parentElement.parentElement;\r\n }\r\n let errorAdded = inputParent.dataset.errorAdded;\r\n inputParent.classList.add(\"validation-error\");\r\n input.classList.add(\"error-input\")\r\n if (errorAdded === \"false\" || !errorAdded) {\r\n // creating the error message p\r\n let eP = document.createElement(\"p\");\r\n eP.setAttribute(\"class\", \"error-msg\");\r\n eP.innerText = \"This input is required\";\r\n inputParent.appendChild(eP);\r\n inputParent.dataset.errorAdded = \"true\";\r\n }\r\n}\r\n\r\n// removes the error from an input\r\nfunction removeError(input) {\r\n let inputParent = input.parentElement;\r\n if (!inputParent.className.includes(\"form-group\")){\r\n inputParent = input.parentElement.parentElement;\r\n }\r\n let errorAdded = inputParent.dataset.errorAdded;\r\n inputParent.classList.remove(\"validation-error\");\r\n input.classList.remove(\"error-input\");\r\n // removing the error message p\r\n if (errorAdded === \"true\") {\r\n inputParent.removeChild(inputParent.lastElementChild);\r\n inputParent.dataset.errorAdded = \"false\";\r\n }\r\n}\r\n\r\n// function to get all required input\r\nfunction getRequiredFields(formGroups) {\r\n let nameList = [\"SELECT\", \"INPUT\", \"TEXTAREA\"];\r\n let inputs = [];\r\n // let formGroups = document.getElementsByClassName(\"form-group\");\r\n for (let i = 0; i < formGroups.length; i++) {\r\n let children = formGroups[i].children;\r\n for (let j = 0; j < children.length; j++) {\r\n if (children[j].tagName === \"DIV\"){\r\n let grandChildren = children[j].children;\r\n for (let a = 0; a < grandChildren.length; a++) {\r\n if (nameList.includes(grandChildren[a].tagName)) {\r\n if (grandChildren[a].required) {\r\n inputs.push(grandChildren[a]);\r\n }\r\n }\r\n }\r\n }\r\n else{\r\n if (nameList.includes(children[j].tagName)) {\r\n if (children[j].required) {\r\n inputs.push(children[j]);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return inputs\r\n}\r\n\r\n// checks if the form will be ignored form validation.\r\nfunction getIgnored(form, ignoredClasses) {\r\n let isIgnored = false;\r\n let classes = form.classList;\r\n if (ignoredClasses.length > 0) {\r\n classes.forEach((_class) => {\r\n if (ignoredClasses.includes(_class)) {\r\n isIgnored = true;\r\n return isIgnored;\r\n }\r\n });\r\n }\r\n return isIgnored\r\n}\r\n\r\n// Checks if the form will be validated.\r\nfunction isValidate(form, ignoredClasses) {\r\n let enableValidate = true;\r\n let classes = form.classList;\r\n if (ignoredClasses.length > 0) {\r\n classes.forEach((_class) => {\r\n if (ignoredClasses.includes(_class)) {\r\n enableValidate = false;\r\n return enableValidate;\r\n }\r\n });\r\n }\r\n return enableValidate\r\n}\r\n\r\n// Confirms if a form will only validate the form on submit, only.\r\nfunction getValidateOnlyValidateOnSubmit(form, validateOnlyOnSubmit, enableValidation) {\r\n let validateOnSubmit = false;\r\n let trueFlags = [\"all\", \"__all__\", \"*\", \"true\"];\r\n if (enableValidation) {\r\n let classes = form.classList;\r\n if (trueFlags.includes(validateOnlyOnSubmit[0])) {\r\n validateOnSubmit = true;\r\n return true;\r\n }\r\n else {\r\n classes.forEach((_class) => {\r\n if (validateOnlyOnSubmit.includes(_class)) {\r\n validateOnSubmit = true;\r\n return validateOnlyOnSubmit;\r\n }\r\n });\r\n }\r\n }\r\n return validateOnSubmit;\r\n}\r\n\r\n// adds listener logic to the form\r\nfunction _Initialize(form={}){\r\n if (!form.ignored || form.enableValidation) {\r\n // add all listeners to each form\r\n addAsterisks(form);\r\n if (!form.validateOnlyOnSubmit) {\r\n validateInputs(form);\r\n }\r\n if (!form.ignored) {\r\n submitValidation(form);\r\n }\r\n }\r\n}\r\n\r\n// function to initialize forms into a json object\r\nfunction _InitializeForms(formNodes, ignoredFormClasses=[], ignoredValidationClasses=[], validateOnlyOnSubmit){\r\n for (let i = 0; i < formNodes.length; i++) {\r\n let currentForm = formNodes[i];\r\n let ignored = getIgnored(currentForm, ignoredFormClasses);\r\n let enableValidation = isValidate(currentForm, ignoredValidationClasses);\r\n let validateOnSubmit = getValidateOnlyValidateOnSubmit(currentForm, validateOnlyOnSubmit, enableValidation);\r\n let _form = {\r\n id: currentForm.id,\r\n form: currentForm,\r\n ignored: ignored,\r\n enableValidation: enableValidation,\r\n validateOnlyOnSubmit: validateOnSubmit,\r\n }\r\n\r\n // adding form functionality\r\n _Initialize(_form);\r\n }\r\n}\n\n//# sourceURL=webpack://fv/./src/js/formFunctions.js?");
129
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ _Initialize: () => (/* binding */ _Initialize),\n/* harmony export */ _InitializeForms: () => (/* binding */ _InitializeForms),\n/* harmony export */ checkForm: () => (/* binding */ checkForm),\n/* harmony export */ csrftoken: () => (/* binding */ csrftoken),\n/* harmony export */ fetchHandleForm: () => (/* binding */ fetchHandleForm)\n/* harmony export */ });\n// ########## Getting the csrf token for the fetch calls ##########\r\nfunction getCookie(name) {\r\n let cookieValue = null;\r\n if (document.cookie && document.cookie !== '') {\r\n const cookies = document.cookie.split(';');\r\n for (let i = 0; i < cookies.length; i++) {\r\n const cookie = cookies[i].trim();\r\n // Does this cookie string begin with the name we want?\r\n if (cookie.substring(0, name.length + 1) === (name + '=')) {\r\n cookieValue = decodeURIComponent(cookie.substring(name.length + 1));\r\n break;\r\n }\r\n }\r\n }\r\n return cookieValue;\r\n}\r\nconst csrftoken = getCookie('csrftoken');\r\n\r\n// ##### Fetch Calls #####\r\n// performs fetch call to view\r\nconst fetchHandleForm = async (form) => {\r\n let formData = new FormData(form);\r\n return await fetch(form.action, {\r\n method: \"POST\",\r\n credentials: \"same-origin\",\r\n headers: {\r\n // \"Accept\": \"m\",\r\n // \"X-Requested-With\": \"XMLHttpRequest\",\r\n \"X-CSRFToken\": csrftoken,\r\n },\r\n body: formData,\r\n }).then(async (response) => {\r\n return response.json();\r\n });\r\n}\r\n// ***** Adding asterisks to labels of required inputs *****\r\nfunction addAsterisks(form) {\r\n // gathering all inputs\r\n let formGroups = document.querySelectorAll(`#${form.id} .form-group`);\r\n let inputs = getRequiredFields(formGroups);\r\n\r\n // adding the required-field class which will add the asterisk\r\n for (let i = 0; i < inputs.length; i++) {\r\n let label = document.querySelector(`label[for=${inputs[i].name}]`);\r\n if (inputs[i].required) {\r\n label.classList.add(\"required-field\");\r\n }\r\n }\r\n}\r\n\r\n// In-line validation on required fields\r\nfunction validateInputs(form) {\r\n // gathering all inputs\r\n let formGroups = document.querySelectorAll(`#${form.id} .form-group`);\r\n let inputs = getRequiredFields(formGroups);\r\n\r\n // adding listeners to each input for validation\r\n for (let i = 0; i < inputs.length; i++) {\r\n inputs[i].addEventListener(\"focusout\", () => {\r\n if (inputs[i].value === \"\" || inputs[i].value === null) {\r\n addError(inputs[i]);\r\n } else {\r\n removeError(inputs[i]);\r\n }\r\n });\r\n }\r\n}\r\n// validateInputs();\r\n\r\n// check form function\r\nfunction checkForm(form) {\r\n let errors = false;\r\n\r\n // gathering all inputs\r\n let formGroups = document.querySelectorAll(`#${form.id} .form-group`);\r\n let inputs = getRequiredFields(formGroups);\r\n\r\n // iterating through all required fields to check for invalidation\r\n for (let i = 0; i < inputs.length; i++) {\r\n let input = inputs[i];\r\n if (input.value === \"\" || !input.value) {\r\n addError(input);\r\n errors = true;\r\n }\r\n }\r\n\r\n return errors\r\n}\r\n\r\n// submit button validation check\r\nfunction submitValidation(form) {\r\n form.form.addEventListener(\"submit\", (e) => {\r\n // preventing default submission behavior\r\n e.preventDefault();\r\n\r\n // gathering all inputs\r\n let f = e.target;\r\n // let formGroups = document.querySelectorAll(`#${form.id} .form-group`);\r\n // let inputs = getRequiredFields(formGroups);\r\n // // let form = document.getElementById(\"form\") !== null ? document.getElementById(\"form\") : document.getElementById(\"userForm\");\r\n let errors = checkForm(f);\r\n\r\n // submitting the form if there aren't any errors\r\n if (!errors) {\r\n form.form.submit();\r\n } else {\r\n let invalidInputs = document.getElementsByClassName(\"validation-error\");\r\n // scroll to the first invalid input\r\n invalidInputs[0].parentElement.scrollIntoView();\r\n }\r\n });\r\n}\r\n\r\n// adds an error to an input\r\nfunction addError(input) {\r\n let inputParent = input.parentElement;\r\n if (!inputParent.className.includes(\"form-group\")){\r\n inputParent = input.parentElement.parentElement;\r\n }\r\n let errorAdded = inputParent.dataset.errorAdded;\r\n inputParent.classList.add(\"validation-error\");\r\n input.classList.add(\"error-input\")\r\n if (errorAdded === \"false\" || !errorAdded) {\r\n // creating the error message p\r\n let eP = document.createElement(\"p\");\r\n eP.setAttribute(\"class\", \"error-msg\");\r\n eP.innerText = \"This input is required\";\r\n inputParent.appendChild(eP);\r\n inputParent.dataset.errorAdded = \"true\";\r\n }\r\n}\r\n\r\n// removes the error from an input\r\nfunction removeError(input) {\r\n let inputParent = input.parentElement;\r\n if (!inputParent.className.includes(\"form-group\")){\r\n inputParent = input.parentElement.parentElement;\r\n }\r\n let errorAdded = inputParent.dataset.errorAdded;\r\n inputParent.classList.remove(\"validation-error\");\r\n input.classList.remove(\"error-input\");\r\n // removing the error message p\r\n if (errorAdded === \"true\") {\r\n inputParent.removeChild(inputParent.lastElementChild);\r\n inputParent.dataset.errorAdded = \"false\";\r\n }\r\n}\r\n\r\n// function to get all required input\r\nfunction getRequiredFields(formGroups) {\r\n let nameList = [\"SELECT\", \"INPUT\", \"TEXTAREA\"];\r\n let inputs = [];\r\n // let formGroups = document.getElementsByClassName(\"form-group\");\r\n for (let i = 0; i < formGroups.length; i++) {\r\n let children = formGroups[i].children;\r\n for (let j = 0; j < children.length; j++) {\r\n if (children[j].tagName === \"DIV\"){\r\n let grandChildren = children[j].children;\r\n for (let a = 0; a < grandChildren.length; a++) {\r\n if (nameList.includes(grandChildren[a].tagName)) {\r\n if (grandChildren[a].required) {\r\n inputs.push(grandChildren[a]);\r\n }\r\n }\r\n }\r\n }\r\n else{\r\n if (nameList.includes(children[j].tagName)) {\r\n if (children[j].required) {\r\n inputs.push(children[j]);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return inputs\r\n}\r\n\r\n// checks if the form will be ignored form validation.\r\nfunction getIgnored(form, ignoredClasses) {\r\n let isIgnored = false;\r\n let classes = form.classList;\r\n if (ignoredClasses.length > 0) {\r\n classes.forEach((_class) => {\r\n if (ignoredClasses.includes(_class)) {\r\n isIgnored = true;\r\n return isIgnored;\r\n }\r\n });\r\n }\r\n return isIgnored\r\n}\r\n\r\n// Checks if the form will be validated.\r\nfunction isValidate(form, ignoredClasses) {\r\n let enableValidate = true;\r\n let classes = form.classList;\r\n if (ignoredClasses.length > 0) {\r\n classes.forEach((_class) => {\r\n if (ignoredClasses.includes(_class)) {\r\n enableValidate = false;\r\n return enableValidate;\r\n }\r\n });\r\n }\r\n return enableValidate\r\n}\r\n\r\n// Confirms if a form will only validate the form on submit, only.\r\nfunction getValidateOnlyValidateOnSubmit(form, validateOnlyOnSubmit, enableValidation) {\r\n let validateOnSubmit = false;\r\n let trueFlags = [\"all\", \"__all__\", \"*\", \"true\"];\r\n if (enableValidation) {\r\n let classes = form.classList;\r\n if (trueFlags.includes(validateOnlyOnSubmit[0])) {\r\n validateOnSubmit = true;\r\n return true;\r\n }\r\n else {\r\n classes.forEach((_class) => {\r\n if (validateOnlyOnSubmit.includes(_class)) {\r\n validateOnSubmit = true;\r\n return validateOnlyOnSubmit;\r\n }\r\n });\r\n }\r\n }\r\n return validateOnSubmit;\r\n}\r\n\r\n// adds listener logic to the form\r\nfunction _Initialize(form={}){\r\n if (!form.ignored || form.enableValidation) {\r\n // add all listeners to each form\r\n addAsterisks(form);\r\n if (!form.validateOnlyOnSubmit) {\r\n validateInputs(form);\r\n }\r\n if (!form.ignored) {\r\n submitValidation(form);\r\n }\r\n }\r\n}\r\n\r\n// function to initialize forms into a json object\r\nfunction _InitializeForms(formNodes, ignoredFormClasses=[], ignoredValidationClasses=[], validateOnlyOnSubmit){\r\n for (let i = 0; i < formNodes.length; i++) {\r\n let currentForm = formNodes[i];\r\n let ignored = getIgnored(currentForm, ignoredFormClasses);\r\n let enableValidation = isValidate(currentForm, ignoredValidationClasses);\r\n let validateOnSubmit = getValidateOnlyValidateOnSubmit(currentForm, validateOnlyOnSubmit, enableValidation);\r\n let _form = {\r\n id: currentForm.id,\r\n form: currentForm,\r\n ignored: ignored,\r\n enableValidation: enableValidation,\r\n validateOnlyOnSubmit: validateOnSubmit,\r\n }\r\n\r\n // adding form functionality\r\n _Initialize(_form);\r\n }\r\n}\n\n//# sourceURL=webpack://fv/./src/js/formFunctions.js?");
130
130
 
131
131
  /***/ })
132
132