jazzband / django-formtools

A set of high-level abstractions for Django forms
https://django-formtools.readthedocs.io
BSD 3-Clause "New" or "Revised" License
794 stars 135 forks source link

Form not moving to next step. #198

Closed BismeetSingh closed 5 months ago

BismeetSingh commented 3 years ago

I am using django 3.1.4 with crispy forms 1.12 and formtools 2.3 and the initial page loads but the next button doesn't do anything. However,the next button does validate the page when crispy forms are replaced with {{ form.as_p }}. It seems the library is incompatible with crispy forms. forms:

class IncomeTaxServiceForm1(forms.ModelForm):
    class Meta:
        model = IncomeTaxService
        labels ={
            'director_assessee':"Name of Assessee (Director)",
            "father_name":"Father's Name",

        }
        fields =("director_assessee","father_name","company_name","pan_number","gender","marital_status",
                 "date_of_birth_for_director","adhar_number","mobile_number","email",
                 "director_identification_number","bank_name",
                 "bank_account_number",
                 "ifsc_code","account_type","address","city","state","pincode")

    def __init__(self, *args, **kwargs):
        super(IncomeTaxServiceForm1, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'income_tax_form'
        self.helper.form_class = 'input1'
        self.helper.form_method = 'post'

class IncomeTaxServiceForm2(forms.ModelForm):
    class Meta:
        model = IncomeTaxService
        labels = {
            ' director_in_any_company': "Are You a Director in Any Company? (Listed and/or Unlisted)",
            'partner_in_any_partnership_firm': "Are You a Partner in Any Partnership Firm?",
            'equity_shares_of_unlisted_company': "Any Equity Shares of Unlisted Company Held as on 1st April, 2019?",
            'equity_shares_of_unlisted_company_purchased': "Any Equity Shares of Unlisted Company Purchased During 1st April, 2019 to 31st March, 2020?",
            'equity_shares_of_unlisted_company_sold': "Any Equity Shares of Unlisted Company Sold During 1st April, 2019 to 31st March, 2020?"

        }
        fields =("director_in_any_company",
                "partner_in_any_partnership_firm",
                "equity_shares_of_unlisted_company",
                "equity_shares_of_unlisted_company_purchased",
                "equity_shares_of_unlisted_company_sold")

    def __init__(self, *args, **kwargs):
        super(IncomeTaxServiceForm2, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'income_tax_form2'
        self.helper.form_class = 'input1'
        self.helper.form_method = 'post'
        self.helper.form_action = 'submit_form'

html:


<p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>

        <form  method="post">

            {{ wizard.management_form }}

            {{ form.non_field_errors }}

            {{ form.field_errors }}

                  {% load crispy_forms_tags %}

                  {% crispy wizard.form %}

                  {% if wizard.steps.prev %}
                  <button name="wizard_goto_step" type="submit" style="background-color:#ef3d5b" value="{{ wizard.steps.first }}">"first step"</button>
                  <button name="wizard_goto_step" type="submit" style="background-color:#ef3d5b" value="{{ wizard.steps.prev }}">Previous </button>
                  {% endif %}

             <input type="submit" value="Next" style="background-color:#ef3d5b" />

                     </form>

views.py

class IncomeTaxWizard(SessionWizardView):
    template_name = "service_forms/income_tax.html"
    def done(self, form_list, **kwargs):
        pass

urls.py

 path('income_tax_form',IncomeTaxWizard.as_view([IncomeTaxServiceForm1, IncomeTaxServiceForm2]), name="income_tax_form"),`
timonweb commented 2 years ago

@BismeetSingh I confirm, I'm observing similar behaviour with django-crispy-forms = "1.14.0" and django-formtools = "2.3". Have you managed to solve the issue?

taylan-gms commented 1 year ago

any updates here? I have the same issue

pfouque commented 6 months ago

I solved this using formnovalidate on these buttons to explicitly tell the browser to skip validation:

{% if wizard.steps.prev %}
    <button type="submit" name="wizard_goto_step" value="{{ wizard.steps.first }}" formnovalidate>
    {% translate "first step" %}
    </button>
    <button type="submit" name="wizard_goto_step" value="{{ wizard.steps.prev }}" formnovalidate>
    {% translate "prev step" %}
    </button>
{% endif %}

EDIT: I can see the documentation has been edited to add this, but not published and the fix wasn't applied to the default templates