Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
How to change HTMX behavior to replace the full web page if form is invalid

If this form submits as invalid, I want to override the htmx and do a HttpRedirectResponse that refreshes the full page instead of just changing the div, #superdiv, contents.

<form id="create_form" action="." method="post" hx-post="." hx-target="#superdiv" hx swap="outerHTML">
        {{ form }}
        <button id="button" type="submit">Create</button>
    </form>

I have been attempting to do this in the def post of my views.

if form.is_valid():
    return self.form_valid(form)
else:
    return HttpResponseRedirect(reverse_lazy("logs:manager_form"))

Would this be achieved better using JavaScript? I am trying my best to sticking to learning only vanilla JavaScript for now.

Thanks for any help.

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

I don't know if you already use it but the django-htmx extension is really good and handy.

You can trigger an entire client refresh from your Django view.

HttpResponseClientRefresh

I hope it is useful ๐Ÿ˜Š

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!