[Answer]-Validation based on previous step

1๐Ÿ‘

โœ…

I think that should do it:

class MyWizard(SessionWizardView):
    def get_form_kwargs(self, step):
        kwargs = {}
        if step == 'second_step':
            cleaned_data = self.get_cleaned_data_for_step('first_step')
            kwargs.update({'first_input': cleaned_data['first_input'] })

        return kwargs

then you pop it in your second form

class SecondForm(forms.Form):
    def __init__(self, *args, **kwargs):
        self.first_input = kwargs.pop('first_input', None)
        super(SecondForm, self).__init__(*args, **kwargs)

    def clean(self):
        super(SecondForm, self).clean()
        if any(self.errors):
            return

        # compare self.first_input with self.cleaned_data['second_input']

        return self.cleaned_data
๐Ÿ‘คmariodev

Leave a comment