QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.83k stars 1.31k forks source link

[🐞] Discrepency between submitting Form with JS and native. #3406

Closed mhevery closed 1 year ago

mhevery commented 1 year ago

Which component is affected?

Qwik Runtime

Describe the bug

      <Form action={favoriteJokeAction}>
        <input type="hidden" name="jokeID" value={dadJokeSignal.value.id} />
        <button name="vote" value="up">
          👍
        </button>
        <button name="vote" value="down">
          👎
        </button>
      </Form>

In the above code when clicking 👍 (or 👎) the submitted form should contain vote=up (or vote=down).

This is the case for native submission when JS is disabled.

In emulated submission with JS enable the button value is not sent (is missing)

Reproduction

stackblitz has problems with actions.

Steps to reproduce

import { component$ } from "@builder.io/qwik";
import { routeLoader$, Form, routeAction$ } from "@builder.io/qwik-city";

const useDadJoke = routeLoader$(async () => {
  const response = await fetch("https://icanhazdadjoke.com/", {
    headers: { Accept: "application/json" },
  });
  return (await response.json()) as {
    id: string;
    status: number;
    joke: string;
  };
});

const useJokeVoteAction = routeAction$((props) => {
  console.log("VOTE", props);
});

export default component$(() => {
  const dadJokeSignal = useDadJoke();
  const favoriteJokeAction = useJokeVoteAction();
  return (
    <div class="section bright">
      <div>{dadJokeSignal.value.joke}</div>
      <Form action={favoriteJokeAction}>
        <input type="hidden" name="jokeID" value={dadJokeSignal.value.id} />
        <button name="vote" value="up">
          👍
        </button>
        <button name="vote" value="down">
          👎
        </button>
      </Form>
    </div>
  );
});

System Info

n/a

Additional Information

No response

manucorporat commented 1 year ago

is this a bug of FormData? we are supposed to be doing the right things here, not sure how we can solve this

mhevery commented 1 year ago

I think FormData is right. The thing which needs to be done is to append the key/value of the input causing the submission.

In abov example there are two buttons. Only one needs to be appended when triggered.

On Fri, Mar 17, 2023 at 6:28 AM Manu MA @.***> wrote:

is this a bug of FormData? we are supposed to be doing the right things here, not sure how we can solve this

— Reply to this email directly, view it on GitHub https://github.com/BuilderIO/qwik/issues/3406#issuecomment-1473846298, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA3KT447GSFLXYGL2OSBRDW4RRI3ANCNFSM6AAAAAAV57WAIY . You are receiving this because you authored the thread.Message ID: @.***>

manucorporat commented 1 year ago

can you provide a repo case in stackblitz so i can debug it?

mhevery commented 1 year ago

Yes: https://stackblitz.com/edit/qwik-starter-zcf6ur?file=src%2Froutes%2Findex.css,src%2Froutes%2Findex.tsx

But there is another issue in SB that prevents this from working. 🤦