Django Formset in General FormView

Hi, I used forms in the general form of a FormView as follows:

class RequestRecommendationView(FormView): template_name = "account/stepfour.html" form_class = formset_factory(StepFourForm) def form_valid(self,form): print form.is_valid() cleaned_data = form.cleaned_data # return redirect(reverse("some_url_name")) 
The form

for formset_factory is as follows:

 class StepFourForm(forms.Form): contact_person = forms.CharField(required=True) email = forms.EmailField(required=True) company = forms.CharField(required=True) request_message = forms.CharField(required=True) 

my html structure is as follows:

 <div style="padding-top:100px;padding-left:10px;"> <h4> Request a Recommendation </h4> <form method="post" action=""> {% csrf_token %} <table id="myForm"> <tbody> {% for f in form %} {% for field in f %} <tr> <td>{{field.label_tag}}</td> <td>{{field}}</td> {% for error in field.errors %} <td><span>{{ error }}</span></td> {% endfor %} </tr> {% endfor %} {% endfor %} </tbody> </table> <button class="btn btn-primary btn-xlarge" type="submit" name="submit">Request Now</button> {{ form.management_form }} </form> </div> 

Then I used django-dynamic-formset ( https://code.google.com/p/django-dynamic-formset/ ) to add / remove additional forms through them:

 <script type="text/javascript"> $(function() { $('#myForm tbody').formset(); }) </script> 

The problem is this: if I leave the form empty (each field is required), it manages to get the form_valid () of my class (although this should not), if I fill out one of the fields (leaving the rest blank), it displays an error message successfully . Why is this happening? What should I do to fix this? provides form_class for all this?

+4
source share

Source: https://habr.com/ru/post/1502020/


All Articles