Django Formsets with ECMAScript 6.
Project description
django-easy-formset
Django Formsets with ECMAScript 6
Installation
Installation is easy using pip and the only requirement is a recent version of Django.
python -m pip install django-easy-formset
Basic app configuration
Then to add the Django Easy Formset to your project add the app easy_formset
to
your INSTALLED_APPS
.
INSTALLED_APPS = [
# ...
"easy_formset",
]
How to use
Video
In template
{% load static %}
<head>
<link rel="stylesheet" href="{% static 'easy_formset/easy_formset.css' %}">
</head>
<body>
<div id="{{ formset.prefix }}">
{{ formset.management_form }}
<template formset-empty-form="{{ formset.prefix }}">
{{ formset.empty_form.as_p }}
<a formset-form-delete="{{ formset.empty_form.prefix }}>Delete</a>
</template>
<div formset-forms="{{ formset.prefix }}">
{% for form in formset.forms %}
<div formset-form>
{{ form.as_p }}
<a formset-form-delete="{{ form.prefix }}>Delete</a>
</div>
{% endfor %}
</div>
<button formset-add="{{ formset.prefix }}">Add Formset</button>
</div>
...
<script src="{% static 'easy_formset/easy_formset.js' %}"></script>
<script>
const formset = new Formset("{{ formset.prefix }}")
</script>
</body>
Custom undo element
// add one root element...
Formset.revertHTML = '<a href="#">Custom undo link...</a>'
const formset = new Formset("{{ formset.prefix }}")
Handle add/deleted events
document.addEventListener('formset:add', (event) => {
// access the form with event.detail.form
})
document.addEventListener('formset:deleted', (event) => {
// access the form with event.detail.form
})
Nested formsets
See examples in tests.testapp
.
Run tests
python -m pip -r requirements.txt
pytest
Run project test
python manage.py runserver
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-easy-formset-0.2.4.tar.gz
.
File metadata
- Download URL: django-easy-formset-0.2.4.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2a0f598f33834e528f66c9b5eac935160619eb20da4303b5cfe7164c692089f |
|
MD5 | 96ad6a134aad296945aca21f08cd84a9 |
|
BLAKE2b-256 | a5554d821a9328471643e0d4b2062441eb2fe5b7f878fbadf3425679640cd3fb |
File details
Details for the file django_easy_formset-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: django_easy_formset-0.2.4-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2334b0edba346aa7656055165d2b3a2540d6e4bda5ab601b9b110c480bfd375 |
|
MD5 | f757fd6703d2953c7ec750fd7d30cda3 |
|
BLAKE2b-256 | c7477afd9187cf4f75a39b40d959052451c433f0c868564955fbee005714d034 |