django-forms-frontend-validation 1.0.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- django_forms_frontend_validation-1.0.0/LICENSE +21 -0
- django_forms_frontend_validation-1.0.0/MANIFEST.in +10 -0
- django_forms_frontend_validation-1.0.0/PKG-INFO +86 -0
- django_forms_frontend_validation-1.0.0/README.md +71 -0
- django_forms_frontend_validation-1.0.0/django_forms_frontend_validation.egg-info/PKG-INFO +86 -0
- django_forms_frontend_validation-1.0.0/django_forms_frontend_validation.egg-info/SOURCES.txt +32 -0
- django_forms_frontend_validation-1.0.0/django_forms_frontend_validation.egg-info/dependency_links.txt +1 -0
- django_forms_frontend_validation-1.0.0/django_forms_frontend_validation.egg-info/requires.txt +1 -0
- django_forms_frontend_validation-1.0.0/django_forms_frontend_validation.egg-info/top_level.txt +1 -0
- django_forms_frontend_validation-1.0.0/formvalidator/__init__.py +0 -0
- django_forms_frontend_validation-1.0.0/formvalidator/admin.py +3 -0
- django_forms_frontend_validation-1.0.0/formvalidator/apps.py +6 -0
- django_forms_frontend_validation-1.0.0/formvalidator/form_utils/__init__.py +1 -0
- django_forms_frontend_validation-1.0.0/formvalidator/form_utils/form_utils.py +21 -0
- django_forms_frontend_validation-1.0.0/formvalidator/forms.py +9 -0
- django_forms_frontend_validation-1.0.0/formvalidator/migrations/__init__.py +0 -0
- django_forms_frontend_validation-1.0.0/formvalidator/models.py +3 -0
- django_forms_frontend_validation-1.0.0/formvalidator/settings.py +14 -0
- django_forms_frontend_validation-1.0.0/formvalidator/static/dist/forms.bundle.js +216 -0
- django_forms_frontend_validation-1.0.0/formvalidator/static/webpack/package-lock.json +2869 -0
- django_forms_frontend_validation-1.0.0/formvalidator/static/webpack/package.json +19 -0
- django_forms_frontend_validation-1.0.0/formvalidator/static/webpack/src/css/style.css +42 -0
- django_forms_frontend_validation-1.0.0/formvalidator/static/webpack/src/js/formFunctions.js +263 -0
- django_forms_frontend_validation-1.0.0/formvalidator/static/webpack/src/js/index.js +2 -0
- django_forms_frontend_validation-1.0.0/formvalidator/static/webpack/webpack.config.js +23 -0
- django_forms_frontend_validation-1.0.0/formvalidator/templates/base.html +26 -0
- django_forms_frontend_validation-1.0.0/formvalidator/templates/formvalidator/sample.html +51 -0
- django_forms_frontend_validation-1.0.0/formvalidator/templates/formvalidator/sample2.html +51 -0
- django_forms_frontend_validation-1.0.0/formvalidator/templates/includes/header.html +18 -0
- django_forms_frontend_validation-1.0.0/formvalidator/tests.py +21 -0
- django_forms_frontend_validation-1.0.0/formvalidator/urls.py +12 -0
- django_forms_frontend_validation-1.0.0/formvalidator/views.py +54 -0
- django_forms_frontend_validation-1.0.0/setup.cfg +4 -0
- django_forms_frontend_validation-1.0.0/setup.py +23 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024-Present Andrew Kyle
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Include the LICENSE and README
|
2
|
+
include LICENSE
|
3
|
+
include README.md
|
4
|
+
|
5
|
+
# Include specific static and template files
|
6
|
+
recursive-include formvalidator/static *
|
7
|
+
recursive-include formvalidator/templates *
|
8
|
+
|
9
|
+
# Exclude the node_modules directory
|
10
|
+
prune formvalidator/static/webpack/node_modules
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: django-forms-frontend-validation
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: A Django app for front-end form validation
|
5
|
+
Home-page: https://github.com/andrew-kyle92/django-frontend-validation
|
6
|
+
Author: Andrew Kyle
|
7
|
+
Author-email: andrew.kyle92@yahoo.com
|
8
|
+
License: MIT
|
9
|
+
Classifier: Framework :: Django
|
10
|
+
Classifier: Programming Language :: Python
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Dist: Django>=3.2
|
15
|
+
|
16
|
+
# django-forms-frontend-validation App
|
17
|
+
___
|
18
|
+
|
19
|
+
This project provides a comprehensive system for handling and validating HTML forms in Django applications. It combines client-side JavaScript-based validation and server-side Python logic for robust form processing.
|
20
|
+
|
21
|
+
The application is designed to streamline the process of form validation, ensuring user inputs meet the requirements before submitting them to the server. The system offers features like automatic required-field validation, error handling, and dynamic CSRF token management for secure data transmission.
|
22
|
+
|
23
|
+
## Features
|
24
|
+
- Client-Side Validation:
|
25
|
+
- Automatically validates required fields.
|
26
|
+
- Displays validation errors inline and dynamically updates them upon correction.
|
27
|
+
- Adds asterisks to labels of required fields for better user clarity.
|
28
|
+
- Server-Side Settings:
|
29
|
+
- Control which forms and fields to ignore during validation.
|
30
|
+
- Define validation behavior, such as enforcing checks only on form submission.
|
31
|
+
- Integration with Django Settings:
|
32
|
+
- Use Django's settings to dynamically configure validation rules.
|
33
|
+
- Secure Fetch Calls:
|
34
|
+
- Includes CSRF token management for secure AJAX-based form submissions.
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
### Setting Up
|
38
|
+
1. Include Required Components:
|
39
|
+
- Include the JavaScript files in your project to enable client-side functionality.
|
40
|
+
- Ensure `form_utils.py` is imported and accessible in your Django app.
|
41
|
+
2. Define Settings in settings.py
|
42
|
+
- Add `formvalidator` to installed apps.
|
43
|
+
```python
|
44
|
+
INSTALLED_APPS = [
|
45
|
+
...,
|
46
|
+
'formvalidator',
|
47
|
+
]
|
48
|
+
```
|
49
|
+
- Configure the following variables to customize the behavior.
|
50
|
+
```python
|
51
|
+
IGNORED_CLASSES = ['example-class', 'example-class-2', ...]
|
52
|
+
IGNORE_VALIDATION = ['example-ignore-validation', ...]
|
53
|
+
VALIDATE_ONLY_ON_SUBMIT = ['all'] # Options: "__all__", specific class names, or leave empty.
|
54
|
+
```
|
55
|
+
3. Initial Forms:
|
56
|
+
- Ensure the `_InitializeForms` method is called during page load to attach validation logic to forms dynamically.
|
57
|
+
To your HTML template with the form, add this.
|
58
|
+
```html
|
59
|
+
<script>
|
60
|
+
// fv (formsvalidator) is exported from forms.bundle.js
|
61
|
+
window.addEventListener("load", () => {
|
62
|
+
let ignoredClasses = {{ form_validator.ignored_classes|safe }}; // add more classes that represent forms you want this script to ignore.
|
63
|
+
let ignoreValidation = {{ form_validator.ignore_validation|safe }}; // add any form classes that you want to ignore validation
|
64
|
+
let validateOnlyOnSubmit = {{ form_validator.validate_only_on_submit|safe }}; // for hitting all forms make index 0 either __all__, all, * or leave blank for false or use false
|
65
|
+
let forms = document.getElementsByTagName("form");
|
66
|
+
// if (form || userForm) {
|
67
|
+
if (forms.length > 0) {
|
68
|
+
// calling specific functions on all forms
|
69
|
+
fv._InitializeForms(forms, ignoredClasses, ignoreValidation, validateOnlyOnSubmit);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
</script>
|
73
|
+
```
|
74
|
+
4. Server-Side Context:
|
75
|
+
- Use the `FormsValidator` class to pass configuration to templates:
|
76
|
+
```python
|
77
|
+
from formvalidator.form_utils import FormsValidator
|
78
|
+
|
79
|
+
|
80
|
+
def my_view(request):
|
81
|
+
form_validator = FormsValidator()
|
82
|
+
context = {
|
83
|
+
'form_validator': form_validator.get_context(),
|
84
|
+
}
|
85
|
+
return render(request, 'my_template.html', context)
|
86
|
+
```
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# django-forms-frontend-validation App
|
2
|
+
___
|
3
|
+
|
4
|
+
This project provides a comprehensive system for handling and validating HTML forms in Django applications. It combines client-side JavaScript-based validation and server-side Python logic for robust form processing.
|
5
|
+
|
6
|
+
The application is designed to streamline the process of form validation, ensuring user inputs meet the requirements before submitting them to the server. The system offers features like automatic required-field validation, error handling, and dynamic CSRF token management for secure data transmission.
|
7
|
+
|
8
|
+
## Features
|
9
|
+
- Client-Side Validation:
|
10
|
+
- Automatically validates required fields.
|
11
|
+
- Displays validation errors inline and dynamically updates them upon correction.
|
12
|
+
- Adds asterisks to labels of required fields for better user clarity.
|
13
|
+
- Server-Side Settings:
|
14
|
+
- Control which forms and fields to ignore during validation.
|
15
|
+
- Define validation behavior, such as enforcing checks only on form submission.
|
16
|
+
- Integration with Django Settings:
|
17
|
+
- Use Django's settings to dynamically configure validation rules.
|
18
|
+
- Secure Fetch Calls:
|
19
|
+
- Includes CSRF token management for secure AJAX-based form submissions.
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
### Setting Up
|
23
|
+
1. Include Required Components:
|
24
|
+
- Include the JavaScript files in your project to enable client-side functionality.
|
25
|
+
- Ensure `form_utils.py` is imported and accessible in your Django app.
|
26
|
+
2. Define Settings in settings.py
|
27
|
+
- Add `formvalidator` to installed apps.
|
28
|
+
```python
|
29
|
+
INSTALLED_APPS = [
|
30
|
+
...,
|
31
|
+
'formvalidator',
|
32
|
+
]
|
33
|
+
```
|
34
|
+
- Configure the following variables to customize the behavior.
|
35
|
+
```python
|
36
|
+
IGNORED_CLASSES = ['example-class', 'example-class-2', ...]
|
37
|
+
IGNORE_VALIDATION = ['example-ignore-validation', ...]
|
38
|
+
VALIDATE_ONLY_ON_SUBMIT = ['all'] # Options: "__all__", specific class names, or leave empty.
|
39
|
+
```
|
40
|
+
3. Initial Forms:
|
41
|
+
- Ensure the `_InitializeForms` method is called during page load to attach validation logic to forms dynamically.
|
42
|
+
To your HTML template with the form, add this.
|
43
|
+
```html
|
44
|
+
<script>
|
45
|
+
// fv (formsvalidator) is exported from forms.bundle.js
|
46
|
+
window.addEventListener("load", () => {
|
47
|
+
let ignoredClasses = {{ form_validator.ignored_classes|safe }}; // add more classes that represent forms you want this script to ignore.
|
48
|
+
let ignoreValidation = {{ form_validator.ignore_validation|safe }}; // add any form classes that you want to ignore validation
|
49
|
+
let validateOnlyOnSubmit = {{ form_validator.validate_only_on_submit|safe }}; // for hitting all forms make index 0 either __all__, all, * or leave blank for false or use false
|
50
|
+
let forms = document.getElementsByTagName("form");
|
51
|
+
// if (form || userForm) {
|
52
|
+
if (forms.length > 0) {
|
53
|
+
// calling specific functions on all forms
|
54
|
+
fv._InitializeForms(forms, ignoredClasses, ignoreValidation, validateOnlyOnSubmit);
|
55
|
+
}
|
56
|
+
});
|
57
|
+
</script>
|
58
|
+
```
|
59
|
+
4. Server-Side Context:
|
60
|
+
- Use the `FormsValidator` class to pass configuration to templates:
|
61
|
+
```python
|
62
|
+
from formvalidator.form_utils import FormsValidator
|
63
|
+
|
64
|
+
|
65
|
+
def my_view(request):
|
66
|
+
form_validator = FormsValidator()
|
67
|
+
context = {
|
68
|
+
'form_validator': form_validator.get_context(),
|
69
|
+
}
|
70
|
+
return render(request, 'my_template.html', context)
|
71
|
+
```
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: django-forms-frontend-validation
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: A Django app for front-end form validation
|
5
|
+
Home-page: https://github.com/andrew-kyle92/django-frontend-validation
|
6
|
+
Author: Andrew Kyle
|
7
|
+
Author-email: andrew.kyle92@yahoo.com
|
8
|
+
License: MIT
|
9
|
+
Classifier: Framework :: Django
|
10
|
+
Classifier: Programming Language :: Python
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Dist: Django>=3.2
|
15
|
+
|
16
|
+
# django-forms-frontend-validation App
|
17
|
+
___
|
18
|
+
|
19
|
+
This project provides a comprehensive system for handling and validating HTML forms in Django applications. It combines client-side JavaScript-based validation and server-side Python logic for robust form processing.
|
20
|
+
|
21
|
+
The application is designed to streamline the process of form validation, ensuring user inputs meet the requirements before submitting them to the server. The system offers features like automatic required-field validation, error handling, and dynamic CSRF token management for secure data transmission.
|
22
|
+
|
23
|
+
## Features
|
24
|
+
- Client-Side Validation:
|
25
|
+
- Automatically validates required fields.
|
26
|
+
- Displays validation errors inline and dynamically updates them upon correction.
|
27
|
+
- Adds asterisks to labels of required fields for better user clarity.
|
28
|
+
- Server-Side Settings:
|
29
|
+
- Control which forms and fields to ignore during validation.
|
30
|
+
- Define validation behavior, such as enforcing checks only on form submission.
|
31
|
+
- Integration with Django Settings:
|
32
|
+
- Use Django's settings to dynamically configure validation rules.
|
33
|
+
- Secure Fetch Calls:
|
34
|
+
- Includes CSRF token management for secure AJAX-based form submissions.
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
### Setting Up
|
38
|
+
1. Include Required Components:
|
39
|
+
- Include the JavaScript files in your project to enable client-side functionality.
|
40
|
+
- Ensure `form_utils.py` is imported and accessible in your Django app.
|
41
|
+
2. Define Settings in settings.py
|
42
|
+
- Add `formvalidator` to installed apps.
|
43
|
+
```python
|
44
|
+
INSTALLED_APPS = [
|
45
|
+
...,
|
46
|
+
'formvalidator',
|
47
|
+
]
|
48
|
+
```
|
49
|
+
- Configure the following variables to customize the behavior.
|
50
|
+
```python
|
51
|
+
IGNORED_CLASSES = ['example-class', 'example-class-2', ...]
|
52
|
+
IGNORE_VALIDATION = ['example-ignore-validation', ...]
|
53
|
+
VALIDATE_ONLY_ON_SUBMIT = ['all'] # Options: "__all__", specific class names, or leave empty.
|
54
|
+
```
|
55
|
+
3. Initial Forms:
|
56
|
+
- Ensure the `_InitializeForms` method is called during page load to attach validation logic to forms dynamically.
|
57
|
+
To your HTML template with the form, add this.
|
58
|
+
```html
|
59
|
+
<script>
|
60
|
+
// fv (formsvalidator) is exported from forms.bundle.js
|
61
|
+
window.addEventListener("load", () => {
|
62
|
+
let ignoredClasses = {{ form_validator.ignored_classes|safe }}; // add more classes that represent forms you want this script to ignore.
|
63
|
+
let ignoreValidation = {{ form_validator.ignore_validation|safe }}; // add any form classes that you want to ignore validation
|
64
|
+
let validateOnlyOnSubmit = {{ form_validator.validate_only_on_submit|safe }}; // for hitting all forms make index 0 either __all__, all, * or leave blank for false or use false
|
65
|
+
let forms = document.getElementsByTagName("form");
|
66
|
+
// if (form || userForm) {
|
67
|
+
if (forms.length > 0) {
|
68
|
+
// calling specific functions on all forms
|
69
|
+
fv._InitializeForms(forms, ignoredClasses, ignoreValidation, validateOnlyOnSubmit);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
</script>
|
73
|
+
```
|
74
|
+
4. Server-Side Context:
|
75
|
+
- Use the `FormsValidator` class to pass configuration to templates:
|
76
|
+
```python
|
77
|
+
from formvalidator.form_utils import FormsValidator
|
78
|
+
|
79
|
+
|
80
|
+
def my_view(request):
|
81
|
+
form_validator = FormsValidator()
|
82
|
+
context = {
|
83
|
+
'form_validator': form_validator.get_context(),
|
84
|
+
}
|
85
|
+
return render(request, 'my_template.html', context)
|
86
|
+
```
|
@@ -0,0 +1,32 @@
|
|
1
|
+
LICENSE
|
2
|
+
MANIFEST.in
|
3
|
+
README.md
|
4
|
+
setup.py
|
5
|
+
django_forms_frontend_validation.egg-info/PKG-INFO
|
6
|
+
django_forms_frontend_validation.egg-info/SOURCES.txt
|
7
|
+
django_forms_frontend_validation.egg-info/dependency_links.txt
|
8
|
+
django_forms_frontend_validation.egg-info/requires.txt
|
9
|
+
django_forms_frontend_validation.egg-info/top_level.txt
|
10
|
+
formvalidator/__init__.py
|
11
|
+
formvalidator/admin.py
|
12
|
+
formvalidator/apps.py
|
13
|
+
formvalidator/forms.py
|
14
|
+
formvalidator/models.py
|
15
|
+
formvalidator/settings.py
|
16
|
+
formvalidator/tests.py
|
17
|
+
formvalidator/urls.py
|
18
|
+
formvalidator/views.py
|
19
|
+
formvalidator/form_utils/__init__.py
|
20
|
+
formvalidator/form_utils/form_utils.py
|
21
|
+
formvalidator/migrations/__init__.py
|
22
|
+
formvalidator/static/dist/forms.bundle.js
|
23
|
+
formvalidator/static/webpack/package-lock.json
|
24
|
+
formvalidator/static/webpack/package.json
|
25
|
+
formvalidator/static/webpack/webpack.config.js
|
26
|
+
formvalidator/static/webpack/src/css/style.css
|
27
|
+
formvalidator/static/webpack/src/js/formFunctions.js
|
28
|
+
formvalidator/static/webpack/src/js/index.js
|
29
|
+
formvalidator/templates/base.html
|
30
|
+
formvalidator/templates/formvalidator/sample.html
|
31
|
+
formvalidator/templates/formvalidator/sample2.html
|
32
|
+
formvalidator/templates/includes/header.html
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
Django>=3.2
|
django_forms_frontend_validation-1.0.0/django_forms_frontend_validation.egg-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
formvalidator
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
from .form_utils import FormsValidator
|
@@ -0,0 +1,21 @@
|
|
1
|
+
from django.conf import settings
|
2
|
+
|
3
|
+
|
4
|
+
class FormsValidator:
|
5
|
+
"""
|
6
|
+
Provides access to settings for ignored classes and validation behavior.
|
7
|
+
"""
|
8
|
+
def __init__(self):
|
9
|
+
self.ignored_classes = settings.IGNORED_CLASSES
|
10
|
+
self.ignore_validation = settings.IGNORE_VALIDATION
|
11
|
+
self.validate_only_on_submit = settings.VALIDATE_ONLY_ON_SUBMIT
|
12
|
+
|
13
|
+
def get_context(self):
|
14
|
+
"""
|
15
|
+
Returns a dictionary for use in template contexts
|
16
|
+
"""
|
17
|
+
return {
|
18
|
+
'ignored_classes': self.ignored_classes,
|
19
|
+
'ignore_validation': self.ignore_validation,
|
20
|
+
'validate_only_on_submit': self.validate_only_on_submit
|
21
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from django import forms
|
2
|
+
|
3
|
+
|
4
|
+
class SampleForm(forms.Form):
|
5
|
+
first_name = forms.CharField(label='First Name', max_length=100, required=True, widget=forms.TextInput(attrs={'class': 'form-control'}))
|
6
|
+
last_name = forms.CharField(label='Last Name', max_length=100, required=True, widget=forms.TextInput(attrs={'class': 'form-control'}))
|
7
|
+
email = forms.EmailField(label='Email', max_length=100, required=True, widget=forms.TextInput(attrs={'class': 'form-control'}))
|
8
|
+
phone = forms.CharField(label='Phone Number', max_length=100, required=False, widget=forms.TextInput(attrs={'class': 'form-control'}))
|
9
|
+
address = forms.CharField(label='Address', max_length=100, required=False, widget=forms.Textarea(attrs={'class': 'form-control', 'rows': 5, 'cols': 50}))
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# ##### Form Configs #####
|
2
|
+
# A list of HTML classes of forms you want to ignore, completely
|
3
|
+
IGNORED_CLASSES = []
|
4
|
+
|
5
|
+
# Ignoring validation doesn't automatically assume you're omitting the form from being
|
6
|
+
# the form submittal process. It literally just means you would like to ignore all validation.
|
7
|
+
IGNORE_VALIDATION = [] + IGNORED_CLASSES
|
8
|
+
|
9
|
+
# A list of classes where the validation is done only after the submit button has been clicked.
|
10
|
+
# the types can be boolean, string, or list
|
11
|
+
# the string keyword options are 'all', '__all__', '*'
|
12
|
+
# if you would like to keep the type as an array, but still want to hit all forms, you can just set
|
13
|
+
# index 0 as one of those keywords
|
14
|
+
VALIDATE_ONLY_ON_SUBMIT = ["*"]
|