-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[馃悶]Form gets checkbox data #6211
Comments
@rendaoer hi, I would be willing to work on it. Can you assign me as an assignee? |
@yousefmarey12 here ya go 馃槃 |
@thejackshelton I am done, do I PR in the reproduction repo or where exactly do I submit the PR? |
https://github.com/QwikDev/qwik/blob/main/CONTRIBUTING.md The contributing file here goes in-depth on how to make a PR to the Qwik repo. Did you find the solution in the application? Or did you need to change something in the Qwik repo? |
thank you all |
@thejackshelton I found the solution in the application. |
The Complex Forms Docs says that you get an object and not an array as a result of the form submission. In your case, having a form name of just "worlds" would just return an object that has "worlds" as a property and ONE value since it's a key-value pair. The solution is to make the form like this <label for="w1">A</label>
<input id="w1" name="worlds.A" type="checkbox" value="A" />
<label for="w2">B</label>
<input id="w2" name="worlds.B" type="checkbox" value="B" />
<label for="w3">C</label>
<input id="w3" name="worlds.C" type="checkbox" value="C" />
<button type="submit">Submit</button> This will submit only a worlds object but its value will be the ones that you checked. The ones that you checked will of course, contain the actual value. Now if you really want an array then you can do export const useSubmitForm = routeAction$((data) => {
console.log(inspect(Object.values(data.worlds), { depth: null })); // consoles the array
zod$({ worlds: z.array(z.string()) });
}); This makes an array of the values of data.worlds and that's the array of all checked boxes for you. Did I solve your problem? p.s inspect is just a built-in function in node just to help me read the values. |
@yousefmarey12 |
Hey @rendaoer! If you don't find the API intuitive, you could make a feature request in this repo with some context, the preferred API and the reasoning behind it. PR's are always welcome too 馃挭 I'm going to close this issue, as it is not a bug in core or qwik city, and @yousefmarey12 has taken the time to find a solution for ya that works (and is documented) |
Which component is affected?
Qwik City (routing)
Describe the bug
The form uses action to submit multiple CheckBox data and cannot obtain the data array. Only a single CheckBox data can be obtained
Reproduction
https://github.com/rendaoer/qwik-app
Steps to reproduce
pnpm run dev
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: