Open colelawrence opened 3 weeks ago
Thanks for this feedback. Did you check the documentation about this? This new approach is more predictable and maintainable.
Thanks for this feedback. Did you check the documentation about this? This new approach is more predictable and maintainable.
Yes, I love this as an improvement! I think it is much clearer and a better UX for larger forms.
But, for an app like mine which uses route actions heavily with rich-text data, the 1.7.0 implementation is a breaking change with no easy fix.
I also believe the types created are incorrect when there are refinements made on the object level (see my example, and understand there is no place to find the Zod error in the existing TypeScript type).
Was my use case and reproduction understood?
@tzdesign do you have any ideas for this?
@colelawrence what do you expect to output?
In the end if you don't know what you get, you can always check by object keys if there are errors. In your case you could get all errors back by going throw the Record type and find all with pm_title
// NOT TESTED ;-)
export default component$(() => {
const valid = useValidation();
const pmTitleErrors = useComputed$(() => {
const errors = valid.value?.fieldErrors ?? {}
return Object.entries(errors).reduce<string[]>((result,[key,value]) => {
if(key.includes("pm_title") && value !== undefined){
result.push(value)
}
return result
},[])
})
return <>{pmTitleErrors.value.join(",")}</>;
});
While writing this feature I never thought custom will come into play. If this is to complex for you, you can also opt-out and make a custom script inside the routaction without passing validation.
@gioboa I would not call this a bug. If the type is not loose, the feature is helping you a lot with complex types as @colelawrence describes.
Having custom zod types is complex in general. I made the change, because if you use complex forms, the flatten errors are pretty bad having only the first level of keys makes it impossible to guess which error belongs to which field.
Which component is affected?
Qwik Runtime
Describe the bug
A recently released change to how the
zod$
types, causes my previously compiling TypeScript to break, and I don't know how to fix my code without managing the validation entirely within every routeAction$ which accepts rich-text.I depended on Zod flattening the errors, because I am using ProseMirror to prepare JSON that is submitted into the form. In this case, I am submitting programmatically the JSON value of my rich-text editors.
But, the types are implemented in such a way that assumes that every property (recursively) in the
zod$
type, could have an error attached to it.As printed in IDE:
Reproduction
https://stackblitz.com/edit/qwik-1-7-0-fielderrors-pm-obj?file=src%2Froutes%2Findex.tsx
Steps to reproduce
Use any custom zod object that can have its own validation / refinement.
System Info
Additional Information
No response