Comments (5)
Amazing! I’ll scope it out soon, thanks!
from modular-forms.
If I understand you correctly, you want to convert a comma separated string of emails into an array. This would mean that the input of a field has a different type than the output. Currently this behavior is not supported by Modular Forms. Modular Forms currently uses the schema only for validation and ignores its output. I think the errors will go away if you use z.input
instead of z.infer
.
You can now do the following: If you need the array in your component, I suggest to do the conversion with (or without) your schema in useComputed$
independently from Modular Forms. If you need the array in your action, I recommend to do the conversion directly in the action yourself.
Furthermore, if you are interested in saving bundle size, you can validate your form with my new project Valibot: https://github.com/fabian-hiller/valibot
from modular-forms.
Thanks this was really helpful!
I've ended up validating the emails using a custom schema and then joining/splitting the strings in the action as suggested.
Does zod import a large bundle size even after qwik optimisations and will your library work with Qwik and modular forms out of the box? I've added an issue in my tracker to take a look at your library soon, a quick glance and it looks great!
For reference, this is my solution to the problem if anyone else ever needs it:
function splitEmails(val: string) {
return (val as string)
.split(/,\s*/)
.map((e) => e.trim())
.filter((e) => !!e)
}
const emailList = z.custom<string>((val) => {
const emails = splitEmails(val as string)
const valid = z.array(z.string().email()).safeParse(emails)
return valid.success
}, $localize`Please check all emails are valid`)
const schema = z
.object({
billings: emailList,
})
.strict()
type NotificationsForm = z.infer<typeof schema>
export const useFormAction = formAction$<NotificationsForm>(async (data, ev) => {
// call splitEmails(data.billings) and save data
}, zodForm$(schema))
from modular-forms.
Yes Zod currently requires at least 11 KB, even for simple schemas. Valibot is supported in the latest version of Modular Forms in conjunction with Qwik. Native support in Qwik independent of Modular Forms will probably follow next week.
https://modularforms.dev/qwik/guides/validate-your-fields#schema-validation
from modular-forms.
You can check the bundle size with bundlejs.
Zod: https://bundlejs.com/?q=zod&treeshake=%5B%7B+string+%7D%5D
Valibot: https://bundlejs.com/?q=valibot&treeshake=%5B%7B+string+%7D%5D
from modular-forms.
Related Issues (20)
- Qwik "special form" file uploading HOT 1
- onFormComplete for modular forms? HOT 3
- Runtime Error with 'FormError' Execution in Development Mode using QwikJS v1.2.6 and ModularForms v0.18.1 HOT 10
- Deno Compatibility? HOT 2
- vue support? HOT 3
- Conflict with dependency HOT 7
- How to validate a specific field when input changes (Solid) HOT 6
- Solid Kobalte Select example not working HOT 14
- Update peer dependencies for qwik HOT 2
- Confirm password and password validation HOT 1
- Qwik - Example to show confirmation dialog before submitting the form HOT 1
- More bugs with getValues HOT 3
- custom validators need some context, any context HOT 5
- defaultFilters HOT 1
- more critical bugs - this time getvalue on object HOT 10
- Bug: Unable to Edit Input in Modular Form in Production Mode (React ) HOT 3
- Are there any plans to add type validation to the "Typebox" library? HOT 1
- Pattern for creating a form component HOT 4
- Error occurring when using Valibot validation. HOT 4
- `formStore.element.submit()` causes page reload at Qwik HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modular-forms.