{ "info": { "author": "Uros Trstenjak", "author_email": "uros.trstenjak@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "============================\nDjango Bootstrap Modal Forms\n============================\n\nA Django plugin for creating AJAX driven forms in Bootstrap modal.\n\nLive Demo\n=========\n\nDemo_\n\n.. _Demo: https://trco.si/dbmf/\n\nInstallation\n============\n\n1. Install ``django-bootstrap-modal-forms``::\n\n $ pip install django-bootstrap-modal-forms\n\n2. Add ``bootstrap_modal_forms`` to your INSTALLED_APPS in settings.py::\n\n INSTALLED_APPS = [\n ...\n 'bootstrap_modal_forms',\n ...\n ]\n\n3. Include Bootstrap, jQuery and ``jquery.bootstrap.modal.forms.js`` on every page where you would like to set up the AJAX driven Django forms in Bootstrap modal.\n\nIMPORTANT: Adjust Bootstrap and jQuery file paths to match yours, but include ``jquery.bootstrap.modal.forms.js`` exactly as in code bellow.\n\n.. code-block:: html+django\n\n
\n \n \n\n \n \n \n \n \n \n \n\nHow it works?\n=============\n.. code-block:: html\n\n index.html\n\n \n\n1. Click event on html element instantiated with ``modalForm`` opens modal\n2. Form at ``formURL`` is appended to the modal\n3. On submit the form is POSTed via AJAX request to ``formURL``\n4. **Unsuccessful POST request** returns errors, which are shown in modal\n5. **Successful POST request** submits the form and redirects to ``success_url`` and shows ``success_message``, which are both defined in related Django view\n\nUsage\n=====\n\n1. Form\n*******\n\nDefine ModelForm and inherit built-in form ``BSModalForm``.\n\n.. code-block:: python\n\n forms.py\n\n from .models import Book\n from bootstrap_modal_forms.forms import BSModalForm\n\n class BookForm(BSModalForm):\n class Meta:\n model = Book\n fields = ['title', 'author', 'price']\n\n2. Form's html\n**************\n\nDefine form's html and save it as Django template.\n\n- Bootstrap 4 modal elements are used in this example.\n- Button triggering the submission should have type attribute set to ``\"button\"`` and not ``\"submit\"``.\n- Add ``class=\"submit-btn\"`` or custom ``submitBtn`` class (see paragraph **Options**) to this button.\n- Form will POST to ``formURL`` defined in #6.\n- Add ``class=\"invalid\"`` or custom ``errorClass`` (see paragraph **Options**) to the elements that wrap the fields.\n- ``class=\"invalid\"`` acts as a flag for the fields having errors after the form has been POSTed.\n\n.. code-block:: html\n\n book/create_book.html\n\n \n\n3. Class-based view\n*******************\n\nDefine a class-based view BookCreateView and inherit from built-in generic view ``BSModalCreateView``. BookCreateView processes the form defined in #1, uses the template defined in #2 and redirects to ``success_url`` showing ``success_message``.\n\n.. code-block:: python\n\n views.py\n\n from django.urls import reverse_lazy\n from .forms import BookForm\n from .models import Book\n from bootstrap_modal_forms.generic import BSModalCreateView\n\n class BookCreateView(BSModalCreateView):\n template_name = 'examples/create_book.html'\n form_class = BookForm\n success_message = 'Success: Book was created.'\n success_url = reverse_lazy('index')\n\n4. URL for the view\n*******************\n\nDefine URL for the view in #3.\n\n.. code-block:: python\n\n from django.urls import path\n from books import views\n\n urlpatterns = [\n path('', views.Index.as_view(), name='index'),\n path('create/', views.BookCreateView.as_view(), name='create_book'),\n ]\n\n5. Bootstrap modal and trigger element\n**************************************\n\nDefine the Bootstrap modal window and html element triggering modal opening.\n\n- Same modal window can be used for multiple ``modalForms`` in single template (see #6).\n- Trigger element (in this example button with ``create-book`` class) is used for instantiation of ``modalForm`` in #6.\n- Any element can be trigger element as long as ``modalForm`` is bound to it.\n- Click event on trigger element loads form's html from #2 within ```` and sets action attribute of the form to ``formURL`` set in #6.\n\n.. code-block:: html+django\n\n index.html\n\n