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.empty_form.as_p }}
<a formset-form-delete>Delete</a>
</template>
<div formset-forms>
{% for form in formset.forms %}
<div formset-form>
{{ form.as_p }}
<a formset-form-delete>Delete</a>
</div>
{% endfor %}
</div>
<button formset-add>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
Close
Hashes for django-easy-formset-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e0c403cd29e9bb52c772d14452553f2836eedd293144aba83219726d21e0d5c |
|
MD5 | c665d528710c3f92d6a04231d8ab8143 |
|
BLAKE2b-256 | 9fb829cb1349560e5b842217b2ee825cb79246247027732f0d16fb23bfc4e285 |
Close
Hashes for django_easy_formset-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d29827d78cde35d4f6b7e8a078058cbb1736347e2bcc82ca2046df10161aa8b0 |
|
MD5 | 6259e92508af1f2095d184c16e60fb5d |
|
BLAKE2b-256 | ac7021423c266e01c322503864a31c5e324831ea58ea6c14675d17d0dda36eb8 |