Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WizardForm should have a form_invalid() method #268

Open
nerdoc opened this issue Mar 15, 2024 · 0 comments · May be fixed by #269
Open

WizardForm should have a form_invalid() method #268

nerdoc opened this issue Mar 15, 2024 · 0 comments · May be fixed by #269

Comments

@nerdoc
Copy link

nerdoc commented Mar 15, 2024

As it is perfectly fine to have no form_valid() method - WizardView provides a done() method for the final good end - there is no way to interact with the view if one form step was invalid, and I want to change the result.

My use case: I mix the forms with some mixins that provide dynamic HTMX updates - if one field is changed, this could trigger a reload of the whole form with different params (querysets, other fields etc) by HTMX.
This must be done using POST, and therefore the form is validated, suddenly showing errors all over the place (empty fields etc).

I don't want that, so I changed the mixin class' form_invalid() method like this in my mixin:

def form_invalid(self, form):
    if self.request.POST.get("_dynamic_reload"):
        form.errors.clear()
    return super().form_invalid(form)

if there was sent a special parameter with the HTMX request, the form errors are cleared. This works reasonably well.

But I can't do that when I subclass WizardView. It could be solved by adding a WizardView.invalid_form() method, which is called instead of just rendering the form manually in post(), and could be overridden then in subclasses if needed.

@nerdoc nerdoc linked a pull request Mar 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant