Replies: 4 comments 8 replies
-
Edit: The text in this post is not how I see it anymore. See comment below #7643 (comment) I'll leave this post here anyway as a background. Maybe it helps someone else who is also on the wrong track regarding I'll offer my take on this. Decoupoling data/rules from UIMy goal when choosing a form library has been to decouple the "form engine" from the visual form. This goal is what led me to Final-Form, which has exactly this philosophy. After realising that maintenance of FF is quite minimal, I looked around and found RHF, which seems to have almost the same philosopy. To me, "register" a field, is the process to allocate storage for the field value at the backend (i.e. RHF). If I register Ideally, the registering should also include any validation rules and all the fields metadata. When time comes for mounting a field (for example on the next page in a wizard), it would be great to have all the metadata at hand, i.e. texts (captions, helptext), styles (icons, colors). This capability does not yet exist in RHF. Final-Form has this and It's great to be able to link any metadata to a registered field. As of now I keep metadata in a separate structure which is keyed with the name of each field. This structure is available to the UI elements via context. Why register fields that might not even be mounted?I might have a very specific use case, but to me this is essential. My forms are organized in tree form. There is a main form, from which sub-forms can be opened. Registered fields can be rendered as input fields or preview fields (readonly) Here is a simple example: Registered fields:
Main form shows:
A subform "Pricing" can be opened, but does not need to be opened. I the user checks |
Beta Was this translation helpful? Give feedback.
-
I don't get why people want to know what's |
Beta Was this translation helpful? Give feedback.
-
I might be biased coming from Final-Form. I saw the But it's always good to simplify stuff. Maybe I have overcomplivated this. I wil do some testing in a branch and see where it takes me. As of now I do the following:
I will try the following instead:
But I'm not sure how to do this:
|
Beta Was this translation helpful? Give feedback.
-
Haha, that was easy. Thank you @bluebill1049 for leading me to a better path. I think two things drove me to the overcomplicated pre-registration concept.
@Moshyfawn I'll take it all back. My post above about registration is not how I see it anymore =) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There're quite a few discussions now with questions on how to get the currently registered fields. Most recent are #7618 and #7620. It raised a couple of question for me:
The "Why?"
I'd think the reason to get the registered input would be something to do with omitting the unregistered value from the submitted data, which can be achieved by providing the
shouldUnregister: true
prop touseForm
hook options.Is it something to do with disabling the field's validation? But the validation (whether it's the HTML validation attributed like
required
or the customvalidation
callback) won't run since the validation requirements are on the field that's unmounted. Having a top level form validation schema can also deal with the field being unmounted (aka disabled): it should factor in the ability to unmount the field that can be omitted by setting the value as optional.The "What?"
I don't have a concrete understanding of what people mean by "registered" input. Is it that the form has the field input's
ref
? But some field (i.e. some UI lib component) don't even expose theirref
. How do you understand what's registered then? Is that the input is uncontrolled and theregister
form method is used to.. "register" it? So, are you looking for the mounted components? If so, what doesn't work with approaches described in the "Why?" section.The "What's missing?"
This question is both "Why?" and "What?" sections combined, I guess.. But I don't want to re-write and rearrange the whole structure of this question lol xD
Beta Was this translation helpful? Give feedback.
All reactions