The button does not work with using the library library <django-formset>

15 views Asked by At

I use the library "Django-formset". It seems that I did everything according to the instructions. The form filtering is triggered. But the button does not respond at all to pressing. There is speculation that this could be due to a label error in template (it comes from using the library). But most likely the reason is different.

Models:

class Brand(models.Model):
    name = models.CharField(max_length=100)


class Car(models.Model):
    name = models.CharField(max_length=100)
    brand = models.ForeignKey('Brand', null=False, blank=False, on_delete=models.CASCADE)


class Trip(models.Model):
    brand = models.ForeignKey('Brand', on_delete=models.CASCADE)
    car = models.ForeignKey('Car', on_delete=models.CASCADE)

Form:

from formset.utils import FormMixin

class TripForm(FormMixin, forms.ModelForm):
    brand = forms.ModelChoiceField(
        label="Brand",
        queryset=Brand.objects.all(),
        widget=Selectize(
            search_lookup='name__icontains',
            placeholder="First, select Brand"
        ),
        required=True,
    )

    car = forms.ModelChoiceField(
        label="Car",
        queryset=Car.objects.all(),
        widget=Selectize(
            search_lookup=['name__icontains'],
            filter_by={'brand': 'brand__id'},
            placeholder="Then, select a Car"
        ),
        required=True,
    )

    class Meta:
        model = Trip
        fields = ('brand', 'car')

View:

from django.views.generic import CreateView
from formset.views import FormViewMixin, FormView

class TripView(FormView, FormViewMixin, CreateView):
    model = Trip
    form_class = TripForm
    success_url = ""
    template_name = 'test.html'

Template:

{% load formsetify %}

<head>
    <script type="module" src="{% static 'formset/js/django-formset.js' %}"></script>
    <script type="text/javascript" src="{% static 'js/jquery.js' %}"></script>
</head>

<body>
  <django-formset endpoint="{{ request.path }}" csrf-token="{{ csrf_token }}">
    {% render_form form %}
    <button type="button" click="submit -> proceed">Submit</button>
  </django-formset>
</body>

enter image description here

0

There are 0 answers