Skip to main content

Coral formsets

Project description

coral-formsets

Extensão para manipular o frontend usando Django FormSets.

Não tem dependência com outro framework/biblioteca javascript.

Documentation

Installation

Para instalar coral-formsets:

pip install coral-formsets

Adicione coral_formsets em INSTALLED_APPS:

INSTALLED_APPS = [
    # other apps
    "coral_formsets",
]

Usage

No seu html adicione o js como no exemplo abaixo.
Nesse exeplo yourapp/form.html é um arquivo referente ao template do seu form, isso garante mais clareza ao seu código:

<!-- yourapp/form.html -->
<div data-form>
  <div style="display: none">{{ form.DELETE }}{{ form.id }}</div>
  {{ form.as_p }}
  <button data-delete>
    delete form
  </button>
</div>
<!-- yourapp/view.html -->
{% load static coral_formset_tags %}
<!DOCTYPE html>
<html>
<body>
  <div data-formset>
    {% render_empty_form_template 'yourapp/form.html' formset as empty_form %}

    {{ formset.management_form }}

    <div data-body>
      {% for form in formset %}
        {% include 'yourapp/form.html' with form=form %}
      {% endfor %}
    </div>

    <button class="formset"
            data-empty-form="{{ empty_form }}"
            data-prefix="{{ formset.prefix }}">
      Add form
    </button>
  </div>

  <script src="{% static 'coral_formsets/js/FormSet.js' %}"></script>
  <script>
    document.querySelectorAll('.formset').forEach(el => {
      new window.coral.FormSet(el);
    });
  </script>
</body>
</html>

A templatetag render_empty_form_template irá transformar o seu formset.empty_form em texto, para depois fazer a inserção do novo form via javascript.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coral-formsets-0.1.2.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

coral_formsets-0.1.2-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file coral-formsets-0.1.2.tar.gz.

File metadata

  • Download URL: coral-formsets-0.1.2.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.5 Linux/5.11.0-43-generic

File hashes

Hashes for coral-formsets-0.1.2.tar.gz
Algorithm Hash digest
SHA256 98ae417e935f5cafd15ddff20c79292b86035b571bc5ed9640e1f7d117457ea9
MD5 7fd55449004542d67ab3f27678d446e2
BLAKE2b-256 9e17fbe4263fd85234567a9cdfb50aa4b215fade9b9b8bcb5076918f5f115168

See more details on using hashes here.

File details

Details for the file coral_formsets-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: coral_formsets-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.5 Linux/5.11.0-43-generic

File hashes

Hashes for coral_formsets-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23e945dbb1c24ba5ac1ffede84fe51fe8a4e685aeebfe761070591cd51f1f803
MD5 bcfe3845c756f1f9735c758c1368134c
BLAKE2b-256 e064b7d5a142c8616202a393c7a87dbf5281087971eb14f8dd3a69bb3e993b50

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page