-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: complex form data #4634
feat: complex form data #4634
Conversation
still supports arrays of strings and objects as it previously did, but now also supports arrays of objects
Run & review this pull request in StackBlitz Codeflow. |
👷 Deploy request for qwik-insights pending review.Visit the deploys page to approve it
|
Looking into the failing tests. |
Happy to merge this soon! amazing job |
more specifically removing purposed depercation notice as bracket notation is needed for multi selects
@ulic75 you don't know how many lines of code we can remove in our project. Thank you so much |
@manucorporat is this something we will see in one of the next releases? |
@ulic75 I start implementing it with a e-commerce cart. If I have a zodSchema like this: export const addressSchema = z.object({
company: z.string().optional(),
workTitle: z.string().optional(),
title: titleSchema.optional(),
salutation: salutationSchema.optional(),
firstname: z.string().min(2),
lastname: z.string().min(2),
street: z.string().min(2),
streetNumber: z.string().min(1),
zip: z.string().min(2),
city: z.string().min(2),
country: z.string().min(2),
phone: z.string().optional(),
mobile: z.string().optional(),
fax: z.string().optional(),
email: emailSchema.optional()
}); The errors I get back are not referenceable: Is it possible to implement the path here as well? This way you need a custom message for everything and flatten the arrays, but this will be a lot of work with multiple schemas. |
@ulic75 ah, manu is just outputting I will check if I can fix it myself next week. If the default zodError always has a path, I would just join the path and we will end up with your dot notation. |
Thought it sounded more zod related. Sounds like a good thing to PR a fix for though. |
@ulic75 I think a qwik reduce like this would be good: const errorByPath: Record<string, string> = result.error.issues.reduce(
(acc, issue) => ({ ...acc, [issue.path.join('.')]: issue.message }),
{} satisfies Record<string, string>
); I can't figure out how to put it in the DataValidator type yet. But when I have time next week, I will take a look. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@builder.io/qwik](https://qwik.builder.io/) ([source](https://togithub.com/BuilderIO/qwik)) | [`1.2.7` -> `1.2.10`](https://renovatebot.com/diffs/npm/@builder.io%2fqwik/1.2.7/1.2.10) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@builder.io%2fqwik/1.2.10?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@builder.io%2fqwik/1.2.10?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@builder.io%2fqwik/1.2.7/1.2.10?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@builder.io%2fqwik/1.2.7/1.2.10?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>BuilderIO/qwik (@​builder.io/qwik)</summary> ### [`v1.2.10`](https://togithub.com/BuilderIO/qwik/releases/tag/v1.2.10) [Compare Source](https://togithub.com/BuilderIO/qwik/compare/v1.2.9...v1.2.10) ##### What's Changed - fix: docs/cookbook/index.mdx link to portal page by [@​Craiqser](https://togithub.com/Craiqser) in [https://github.com/BuilderIO/qwik/pull/5022](https://togithub.com/BuilderIO/qwik/pull/5022) - qwik-labs: fix prettier estree error by [@​gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/5027](https://togithub.com/BuilderIO/qwik/pull/5027) - insights: add existsSync check by [@​gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/5026](https://togithub.com/BuilderIO/qwik/pull/5026) - chore(insights): correct DB migration script by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5024](https://togithub.com/BuilderIO/qwik/pull/5024) - fix(core): Report errors to browser global error handler by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5029](https://togithub.com/BuilderIO/qwik/pull/5029) - style(pnpm-lock.yaml): synchronize lockfile version with version of pnpm in use by [@​jensmeindertsma](https://togithub.com/jensmeindertsma) in [https://github.com/BuilderIO/qwik/pull/4905](https://togithub.com/BuilderIO/qwik/pull/4905) - fix(starter): missing key attrib on `routerHead` component on `1.2.9` by [@​zanettin](https://togithub.com/zanettin) in [https://github.com/BuilderIO/qwik/pull/5025](https://togithub.com/BuilderIO/qwik/pull/5025) - 1.2.10 by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5035](https://togithub.com/BuilderIO/qwik/pull/5035) **Full Changelog**: QwikDev/qwik@v1.2.9...v1.2.10 ### [`v1.2.9`](https://togithub.com/BuilderIO/qwik/releases/tag/v1.2.9) [Compare Source](https://togithub.com/BuilderIO/qwik/compare/v1.2.8...v1.2.9) #### What's Changed - docs: Vercel environment variables by [@​gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/4993](https://togithub.com/BuilderIO/qwik/pull/4993) - refactor(create-qwik): add yargs in create-qwik for better DX by [@​MrWaip](https://togithub.com/MrWaip) in [https://github.com/BuilderIO/qwik/pull/4932](https://togithub.com/BuilderIO/qwik/pull/4932) - feat(adapter): firebase adapter by [@​leifermendez](https://togithub.com/leifermendez) in [https://github.com/BuilderIO/qwik/pull/4778](https://togithub.com/BuilderIO/qwik/pull/4778) - Pr chore by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4994](https://togithub.com/BuilderIO/qwik/pull/4994) - fix: Link component `reload` functionality by [@​zanettin](https://togithub.com/zanettin) in [https://github.com/BuilderIO/qwik/pull/4917](https://togithub.com/BuilderIO/qwik/pull/4917) - docs(qwikcity): html attributes docs page by [@​bab2683](https://togithub.com/bab2683) in [https://github.com/BuilderIO/qwik/pull/4961](https://togithub.com/BuilderIO/qwik/pull/4961) - feat(qwik-city): add a way to get server-side env vars from `onStaticGenerate` by [@​Kocal](https://togithub.com/Kocal) in [https://github.com/BuilderIO/qwik/pull/4912](https://togithub.com/BuilderIO/qwik/pull/4912) - fix(eslint): allow eslint to accept FunctionComponent inside lexical scopes by [@​nynevi](https://togithub.com/nynevi) in [https://github.com/BuilderIO/qwik/pull/4900](https://togithub.com/BuilderIO/qwik/pull/4900) - refactor(cloudflare-pages): allow PlatformCloudflarePages.env to be undefined by [@​bangonkali](https://togithub.com/bangonkali) in [https://github.com/BuilderIO/qwik/pull/4941](https://togithub.com/BuilderIO/qwik/pull/4941) - docs: dynamic alt image by [@​the-r3aper7](https://togithub.com/the-r3aper7) in [https://github.com/BuilderIO/qwik/pull/4999](https://togithub.com/BuilderIO/qwik/pull/4999) - docs: add responsive image recipe by [@​fabiobiondi](https://togithub.com/fabiobiondi) in [https://github.com/BuilderIO/qwik/pull/5002](https://togithub.com/BuilderIO/qwik/pull/5002) - docs: community project update image url by [@​the-r3aper7](https://togithub.com/the-r3aper7) in [https://github.com/BuilderIO/qwik/pull/5000](https://togithub.com/BuilderIO/qwik/pull/5000) - docs: enhance image documentation by [@​fabiobiondi](https://togithub.com/fabiobiondi) in [https://github.com/BuilderIO/qwik/pull/5005](https://togithub.com/BuilderIO/qwik/pull/5005) - added qwik-meet in showcase by [@​harshmangalam](https://togithub.com/harshmangalam) in [https://github.com/BuilderIO/qwik/pull/5007](https://togithub.com/BuilderIO/qwik/pull/5007) - docs: Update index.mdx by [@​the-r3aper7](https://togithub.com/the-r3aper7) in [https://github.com/BuilderIO/qwik/pull/5010](https://togithub.com/BuilderIO/qwik/pull/5010) - docs: update side bar by [@​the-r3aper7](https://togithub.com/the-r3aper7) in [https://github.com/BuilderIO/qwik/pull/5009](https://togithub.com/BuilderIO/qwik/pull/5009) - fix(qwik-city): enable matching route and pathname with an optional t… by [@​pleclech](https://togithub.com/pleclech) in [https://github.com/BuilderIO/qwik/pull/5004](https://togithub.com/BuilderIO/qwik/pull/5004) - docs(image): add details by [@​fabiobiondi](https://togithub.com/fabiobiondi) in [https://github.com/BuilderIO/qwik/pull/5014](https://togithub.com/BuilderIO/qwik/pull/5014) - insights(feat): qwikInsights Vite Plugin + save symbol details by [@​gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/5011](https://togithub.com/BuilderIO/qwik/pull/5011) - chore(insights): Remove deprecated InferModel by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5018](https://togithub.com/BuilderIO/qwik/pull/5018) - fix: add options to qwik vite plugin by [@​jessezhang91](https://togithub.com/jessezhang91) in [https://github.com/BuilderIO/qwik/pull/4983](https://togithub.com/BuilderIO/qwik/pull/4983) - 1.2.9 by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/5021](https://togithub.com/BuilderIO/qwik/pull/5021) #### New Contributors - [@​MrWaip](https://togithub.com/MrWaip) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4932](https://togithub.com/BuilderIO/qwik/pull/4932) - [@​bab2683](https://togithub.com/bab2683) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4961](https://togithub.com/BuilderIO/qwik/pull/4961) - [@​Kocal](https://togithub.com/Kocal) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4912](https://togithub.com/BuilderIO/qwik/pull/4912) - [@​nynevi](https://togithub.com/nynevi) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4900](https://togithub.com/BuilderIO/qwik/pull/4900) - [@​bangonkali](https://togithub.com/bangonkali) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4941](https://togithub.com/BuilderIO/qwik/pull/4941) - [@​pleclech](https://togithub.com/pleclech) made their first contribution in [https://github.com/BuilderIO/qwik/pull/5004](https://togithub.com/BuilderIO/qwik/pull/5004) **Full Changelog**: QwikDev/qwik@v1.2.8...v1.2.9 ### [`v1.2.8`](https://togithub.com/BuilderIO/qwik/releases/tag/v1.2.8) [Compare Source](https://togithub.com/BuilderIO/qwik/compare/v1.2.7...v1.2.8) ##### What's Changed - docs: cleanup by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4945](https://togithub.com/BuilderIO/qwik/pull/4945) - chore: update issue templates by [@​shairez](https://togithub.com/shairez) in [https://github.com/BuilderIO/qwik/pull/4962](https://togithub.com/BuilderIO/qwik/pull/4962) - docs: correctly generate edit URLs for github by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4963](https://togithub.com/BuilderIO/qwik/pull/4963) - Typo in FAQ by [@​ThatJSGuy](https://togithub.com/ThatJSGuy) in [https://github.com/BuilderIO/qwik/pull/4953](https://togithub.com/BuilderIO/qwik/pull/4953) - feat(qwik-city): Show current route in container by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4954](https://togithub.com/BuilderIO/qwik/pull/4954) - fix(docs): add overview link by [@​fabiobiondi](https://togithub.com/fabiobiondi) in [https://github.com/BuilderIO/qwik/pull/4958](https://togithub.com/BuilderIO/qwik/pull/4958) - Towards personalized SSG by [@​eric-burel](https://togithub.com/eric-burel) in [https://github.com/BuilderIO/qwik/pull/4951](https://togithub.com/BuilderIO/qwik/pull/4951) - fix(qwik-auth): remove qaction param from defaultCallbackUrl by [@​ulic75](https://togithub.com/ulic75) in [https://github.com/BuilderIO/qwik/pull/4936](https://togithub.com/BuilderIO/qwik/pull/4936) - fix(qwik-city): cleanup matchRouteRequest by [@​gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/4967](https://togithub.com/BuilderIO/qwik/pull/4967) - fix(auth): Cookies get updated if session returns Updated Cookies by [@​aliyss](https://togithub.com/aliyss) in [https://github.com/BuilderIO/qwik/pull/4960](https://togithub.com/BuilderIO/qwik/pull/4960) - cli(library): fix release script by [@​fabiobiondi](https://togithub.com/fabiobiondi) in [https://github.com/BuilderIO/qwik/pull/4957](https://togithub.com/BuilderIO/qwik/pull/4957) - docs: Improved media, fixed height thumbnails by [@​the-r3aper7](https://togithub.com/the-r3aper7) in [https://github.com/BuilderIO/qwik/pull/4970](https://togithub.com/BuilderIO/qwik/pull/4970) - feat(qwik-city): Adding Script Tag to Head Tag via DocumentHead by [@​Harkunwar](https://togithub.com/Harkunwar) in [https://github.com/BuilderIO/qwik/pull/3230](https://togithub.com/BuilderIO/qwik/pull/3230) - fix: fix cookie parsing to allow invalid uri encoding by [@​jessezhang91](https://togithub.com/jessezhang91) in [https://github.com/BuilderIO/qwik/pull/4915](https://togithub.com/BuilderIO/qwik/pull/4915) - fix(qwikcity): respect X-Forwarded-Host header by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4982](https://togithub.com/BuilderIO/qwik/pull/4982) - chore(docs): fix broken cloudflare build by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4984](https://togithub.com/BuilderIO/qwik/pull/4984) - feat(insights): manage routes and timeline metrics by [@​gioboa](https://togithub.com/gioboa) in [https://github.com/BuilderIO/qwik/pull/4971](https://togithub.com/BuilderIO/qwik/pull/4971) - feat: complex form data by [@​ulic75](https://togithub.com/ulic75) in [https://github.com/BuilderIO/qwik/pull/4634](https://togithub.com/BuilderIO/qwik/pull/4634) - docs(portals): update the portal cookbook example by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4968](https://togithub.com/BuilderIO/qwik/pull/4968) - chore(insights): fix build by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4986](https://togithub.com/BuilderIO/qwik/pull/4986) - fix: only show qwik eslint errors in dev mode by [@​jessezhang91](https://togithub.com/jessezhang91) in [https://github.com/BuilderIO/qwik/pull/4985](https://togithub.com/BuilderIO/qwik/pull/4985) - docs: some progress on the update of the react-cheat-sheet section re… by [@​nsdonato](https://togithub.com/nsdonato) in [https://github.com/BuilderIO/qwik/pull/4976](https://togithub.com/BuilderIO/qwik/pull/4976) - chore(docs): Remove home-page from SSR to improve TTFB metric by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4988](https://togithub.com/BuilderIO/qwik/pull/4988) - Pr no ssr by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4989](https://togithub.com/BuilderIO/qwik/pull/4989) - cli: Add new Markdown route command by [@​brandonpittman](https://togithub.com/brandonpittman) in [https://github.com/BuilderIO/qwik/pull/4955](https://togithub.com/BuilderIO/qwik/pull/4955) - docs: update Prisma limitations by [@​ruheni](https://togithub.com/ruheni) in [https://github.com/BuilderIO/qwik/pull/4241](https://togithub.com/BuilderIO/qwik/pull/4241) - 1.2.8 by [@​mhevery](https://togithub.com/mhevery) in [https://github.com/BuilderIO/qwik/pull/4992](https://togithub.com/BuilderIO/qwik/pull/4992) ##### New Contributors - [@​ThatJSGuy](https://togithub.com/ThatJSGuy) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4953](https://togithub.com/BuilderIO/qwik/pull/4953) - [@​fabiobiondi](https://togithub.com/fabiobiondi) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4958](https://togithub.com/BuilderIO/qwik/pull/4958) - [@​eric-burel](https://togithub.com/eric-burel) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4951](https://togithub.com/BuilderIO/qwik/pull/4951) - [@​aliyss](https://togithub.com/aliyss) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4960](https://togithub.com/BuilderIO/qwik/pull/4960) - [@​brandonpittman](https://togithub.com/brandonpittman) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4955](https://togithub.com/BuilderIO/qwik/pull/4955) - [@​ruheni](https://togithub.com/ruheni) made their first contribution in [https://github.com/BuilderIO/qwik/pull/4241](https://togithub.com/BuilderIO/qwik/pull/4241) **Full Changelog**: QwikDev/qwik@v1.2.7...v1.2.8 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 9pm on sunday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/ascorbic/unpic-img). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi42NC44IiwidXBkYXRlZEluVmVyIjoiMzYuNjQuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->
@ulic75 Can you find your way around the action types? We have a complex cart type with addresses etc. and if cart.invoiceAddress.firstName fails, then you no longer know which field within cart has failed. The errors are flatten inside of cart. cart: string[] |
Overview
Adds support for converting formdata into complex objects and arrays, including arrays of objects. Thank you @fabian-hiller for your ModularForms which I based the code on.
Closes #3183
What is it?
Description
Rewrote the formToObj function to support arrays of objects in addition to everything it supported before (objects, and simple arrays using []).
Checklist: