Modal Widgets#

class CrispyFormModalWidget(form: Form | None = None, form_class: type[Form] | None = None, **kwargs: Any)[source]#

Bases: ModalWidget

A modal dialog containing a Django form rendered with django-crispy-forms.

This specialized modal automatically places a form in the modal body, making it easy to create form dialogs for user input. It handles the rendering of the form using the CrispyFormWidget.

Example

from django import forms
from wildewidgets import CrispyFormModalWidget

class ContactForm(forms.Form):
    name = forms.CharField()
    email = forms.EmailField()
    message = forms.CharField(widget=forms.Textarea)

# Create a modal with the form
modal = CrispyFormModalWidget(
    modal_id="contact-modal",
    modal_title="Contact Us",
    form_class=ContactForm
)
form_class#

The form class to instantiate and render in the modal

Type:

type[Form] | None

form#

An already instantiated form to render in the modal

Type:

Form | None

Parameters:
  • form – An instantiated form to render in the modal

  • form_class – A form class to instantiate and render in the modal

  • **kwargs – Additional arguments passed to the parent ModalWidget class (modal_id, modal_title, modal_size)

Raises:

ImproperlyConfigured – If neither form nor form_class is provided

class ModalWidget(modal_id: str | None = None, modal_title: str | None = None, modal_body: str | None = None, modal_size: str | None = None, **kwargs: Any)[source]#

Bases: Block

Renders a Bootstrap 5 Modal dialog.

This widget creates a Bootstrap modal dialog with a header, body, and footer. The modal can be triggered by a button or link with a data-target attribute matching the modal’s ID.

Example

from wildewidgets import ModalWidget, Block

# Create a simple modal
modal = ModalWidget(
    modal_id="example-modal",
    modal_title="Important Information",
    modal_body=Block("This is the modal content"),
    modal_size="lg"
)
template_name#

Path to the template for rendering the modal

Type:

str

modal_id#

Unique identifier for the modal (used in triggering elements)

Type:

str | None

modal_title#

Text to display in the modal header

Type:

str | None

modal_body#

Content to display in the modal body (typically a Block)

Type:

str | None

modal_size#

Size of the modal dialog (None, ‘sm’, ‘lg’, or ‘xl’)

Type:

str | None

Keyword Arguments:
  • modal_id – The CSS ID of the modal

  • modal_title – The title of the modal

  • modal_body – The body of the modal, any Block

  • modal_size – The size of the modal (None, ‘sm’, ‘lg’, or ‘xl’)

  • **kwargs – Additional attributes passed to the parent Block class

get_context_data(*args: Any, **kwargs: Any) dict[str, Any][source]#

Prepare the context data for the modal template.

This method adds the modal-specific attributes to the template context to be used in rendering the modal dialog.

Parameters:
  • *args – Variable length argument list

  • **kwargs – Arbitrary keyword arguments

Returns:

The updated context dictionary with modal attributes

Return type:

dict

template_name: str = 'wildewidgets/modal.html'#

The name of the template to use to render this block