Code Monkey home page Code Monkey logo

Comments (6)

ollieh-m avatar ollieh-m commented on July 21, 2024 10

Thanks for the explanation @sstephenson. I’m probably misunderstanding something, but can’t quite see why swapping in HTML returned by the form submission (or even simulating a full page visit using the HTML response) would mess with the browser history... If the form submission is an ajax request, does the browser put the POST or PUT request in its history? If not, why would it be a problem to render HTML returned with a 200 response, in the same way 400-500 responses can now be rendered? 🙇‍♂️

from turbo.

sstephenson avatar sstephenson commented on July 21, 2024 4

Browsers record form submissions in history along with the verb. In a standard "postback" scenario, if you reload the page after submission, or navigate away and then back, you'll see a dialog box like this:

Screen Shot 2020-11-30 at 10 41 41 AM

The forms-must-redirect constraint is what allows us to keep the browser's back, forward, and reload buttons working after any form submission, and without showing a dialog box, since all form submissions result in a visit and all visits are idempotent GET requests.

from turbo.

danjac avatar danjac commented on July 21, 2024 2

I'm running into this issue as well with simple form submissions that re-render the form (i.e. the HTML page) with errors when server validation fails. Is there a reason for this behavior? Is it documented?

from turbo.

cj avatar cj commented on July 21, 2024 1

ah so the Turbo.visit is not a bug, it was because I had render plain https://github.com/cj/app-template/blob/main/app/controllers/test_controller.rb#L11!

from turbo.

cj avatar cj commented on July 21, 2024

So I ended up creating a patch for now to get it working on my end https://github.com/cj/app-template/blob/main/patches/%40hotwired%2Bturbo%2B7.0.0-beta.1.patch, but it led to what might be a bug with Turbo.visit:

CleanShot 2020-12-22 at 20 51 06

This is where I am calling Turbo.visit https://github.com/cj/app-template/blob/main/app/components/form_component/base.js#L122

from turbo.

sstephenson avatar sstephenson commented on July 21, 2024

We intend to allow HTTP 422 responses for form submissions inside frames, but it didn’t make the cut for the initial beta release.

For now, you can try sending a Turbo Streams response that re-renders your form with errors.

from turbo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.