Comments (5)
Yeah this is definitely a bug. Will have to think on how best to fix it considering the visitor will only be called when atoms are found.
Addressing the idea of an "array field" type - I do not agree with the approach of validating the array as a field in something like Zod as opposed using .slice() in your user code and validating each field individually:
- From a UX standpoint you are creating a subpar experience if you're letting users do things they aren't allowed to anyway (i.e. click a button to add a field you KNOW is going to fail validation). You shouldn't give your users footguns. If you want to validate it in spite of that, you could in theory accomplish that in the onSubmit function, as in general you seem to favor shape validations rather than field validations. I don't think there's anything wrong with that conceptually, I just don't consider it a core task of a "form" library, particularly one that aims to be bottom-up.
- From a practicality standpoint, there's no such thing as an "array input". Backends are the ones that interpret particular field names as arrays. So the way it exists in the library is just covering the case of "you want your data in a particular shape".
So IMO your "validation" should really just be bounded configuration on an component or whatever.
from form-atoms.
🎉 This issue has been resolved in version 2.0.0-next.2 🎉
The release is available on:
Your semantic-release bot 📦🚀
from form-atoms.
Works as expected with the next version. Thank you!
I've found a bug. Currently it does not work when array contains another array.
Here is a demo where you could possibly have multiple cities in a form, and for each city multiple people/occupants:
(there is no UI, just static initial data)
https://codesandbox.io/s/form-atoms-v2-array-field-in-array-field-bug-76fvov?file=/src/App.tsx
the submit value is
{
cities: [
{
"1": { name: "Asdfgard", people: [{ name: "Thorus" }] },
name: "Atlantits",
people: [{ name: "Shrek" }],
},
],
}
while expected:
{
cities: [
{ name: "Asdfgard", people: [{ name: "Thorus" }] },
{ name: "Atlantits", people: [{ name: "Shrek" }] },
]
}
from form-atoms.
Will address this, thanks!
from form-atoms.
🎉 This issue has been resolved in version 2.0.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
from form-atoms.
Related Issues (20)
- Set debug labels for the form atoms HOT 3
- Add `clear` action to support controlling `input[type='file']` HOT 3
- Permit array as root form fields HOT 1
- Use atom id instead of 'unnamed-field' in debugLabels HOT 2
- When input is `required` the `_validateCount` increases while the validate function is not being called HOT 9
- Debug label not set in vite HOT 3
- What's the reason for limiting setting the initial value only once? HOT 10
- Pass setter to the `Validate` callback.
- Outdated lockfile? HOT 3
- Release workflow expression syntax error
- Export `validateAtoms` on `formAtom` similarly to `_validateCallback` on `fieldAtom` HOT 1
- Hydration with `useFieldInitialValue` in Next.js renders twice - first empty, then filled input. HOT 21
- onReset callback HOT 6
- Field & Form atoms should be of `PrimitiveAtom` type HOT 4
- Debug label completion HOT 1
- Examples: Validation Option Valibot along with zod HOT 3
- Bug - the `useField` reads value before initialization HOT 1
- Why the additional re-render? HOT 6
- Question: use with Jotai Effect HOT 2
- HowTos: DerivedAtom from the field HOT 6
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 form-atoms.