denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.05k stars 607 forks source link

Input with type=submit inside partial does not submit its own value #2566

Closed Sleepful closed 2 days ago

Sleepful commented 3 days ago

consider:


      <form
        f-partial="/partial/car_type"
        method="post"
      />
            <input
              type="submit"
              class="hidden"
              name="car"
              value="a"/>

when this input is clicked and the form is submitted, the req.formData(); should contain the value { car: "a"}, but it does not. It is empty instead.

marvinhagemeister commented 3 days ago

Is the input inside the form? In the snippet the <form /> tag is self closing or is that a copy & paste error here and the form encapsulates the input element in your app?

Sleepful commented 3 days ago

@marvinhagemeister copy & paste error, my bad. Here is a better copy/paste

            <form
              f-partial={`/load_version`}
              method="post"
            >
              <input
                type="submit"
                name="version"
                value="saved"
                class="m-2 bg-blue-600"
              />
            </form>

then in the route:

  async POST(req, ctx) {
    const form = await req.formData();
    const formValues = Object.fromEntries(form.entries());
    console.log({ formValues });
    // prints empty object for formValues, if I remove partial navigation 
    // and use a standard `action` route, it does display the value though 
marvinhagemeister commented 2 days ago

Good news: Just took a look at this and it is already fixed in main. I'm not sure which exact commit resolved it, but I cannot reproduce it there anymore 🎉