blasferna / django-crispy-formset-modal

📝 A Django app for managing formsets with modals using Django Crispy Forms.
https://blasferna.github.io/django-crispy-formset-modal/
MIT License
13 stars 2 forks source link

Missing Assets for Widgets Used in Formsets #5

Open blasferna opened 1 year ago

blasferna commented 1 year ago

There's an issue with the package where the necessary CSS and JavaScript dependencies for widgets are not loaded when these widgets are placed in a formset within a form. Please note that this issue does not occur when the same widget is added directly to the main form.

imagen

Steps to Reproduce:

The issue is reproducible using the django-bootstrap-datepicker-plus package with the following steps:

  1. Install the package: pip install django-bootstrap-datepicker-plus

  2. Add it to INSTALLED_APPS:

    INSTALLED_APPS = [
        "bootstrap_datepicker_plus",
    ]
  3. Create a custom widget without redefining the CSS and JavaScript:

    from bootstrap_datepicker_plus.widgets import (
        DatePickerInput,
        TimePickerInput
    )
    
    class DatePickerWidget(DatePickerInput):
        def __init__(self, attrs=None, format=None):
            attrs = attrs or {}
            attrs.update({'class': 'datepicker'})
            super(DatePickerWidget, self).__init__(attrs, format)
  4. Assign the custom widget to a formset example (in this case, PaymentTermForm):

    from demo.widgets import DatePickerWidget
    
    class PaymentTermForm(forms.ModelForm):
        def __init__(self, *args, **kwargs):
            ...
        class Meta:
            model = PaymentTerm
            fields = "__all__"
            widgets = {"due_date": DatePickerWidget}