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>Delete</a>
</template>
<div formset-forms="{{ formset.prefix }}">
{% for form in formset.forms %}
<div formset-form>
{{ form.as_p }}
<a formset-form-delete>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
Close
Hashes for django-easy-formset-0.2.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b22efc78a483d316dd6cdfe02b1c643927ec78025588ece70c475cb61d07f790 |
|
MD5 | 4177978041c8b409b993f2d1fc62e4de |
|
BLAKE2b-256 | ce80ebfd3f0a1d3ec7d07c666acde7941b1e457bcc414d00f90cb8215904ddd3 |
Close
Hashes for django_easy_formset-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b52df4a7eae3553d9d30f0408b3be3a38161a0b454dfa5b7365a521c822edc5 |
|
MD5 | e4db57884e2c16958d57e0d8b4b39579 |
|
BLAKE2b-256 | 3e0f48b167e472c6d6d730724e95554f4c275ade4248861590da05ab8da845b1 |