Skip to content
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

Support initializing form fields outside of the build method #462

Closed
VOIDCRUSHER opened this issue Sep 16, 2020 · 3 comments
Closed

Support initializing form fields outside of the build method #462

VOIDCRUSHER opened this issue Sep 16, 2020 · 3 comments
Labels
awaiting author response Waiting for author of issue to respond with more info enhancement New feature or request Stale

Comments

@VOIDCRUSHER
Copy link
Contributor

Often times, we have collections of related forms where at least one form is not immediately rendered onscreen and therefore not registered to the form key. The most common of these situations is when we have a multi-paged or tabbed form. In such cases, it's difficult, if not impossible at times to validate the collection of forms or even a single form rendered on screen (if it depends on some other form on another page or tab). This isn't a problem if a user is guaranteed to walk through the forms sequentially but very often we find the use case where the user want's to start on a specific page and then leave immediately after editing a particular topic, leading to validation errors.

Lets walk through an example:

Let's consider the scenario where we have some sort of university housing form. Users can go to the an Edit Profile page to edit their information which is automatically saved on exit but only after a successful form validation. The user's profile data is spread across two tabs, each containing a form with it's own form key, for their personal and housing data respectively.

Let's now say that the housing form has a form field that actually depends on values in one or more fields on the personal data form to validate. If the personal profile tab is always first to be rendered when the user enters the Edit Profile page, (because it is attached to the first tab), then there is no problem to validate on exit. Both forms must have been rendered and field values registered to their form keys after navigating over to the housing data tab from the initial personal data tab.

However, what happens when some action from outside the Edit Profile page navigates us directly to the housing data tab? The form will render without issue and the user, thinking all is well, edits a few fields on the housing tab and attempts to exit. Now we have a problem.The action errors out because our global key for the personal data form, referenced in our validation call in that housing data form field, is null. We never navigated to it.

This is just one example but similar situations present themselves in other multipage forms, very common in profile or carousel-like user onboarding forms.

I don't know what the solution should be but I think this is a common enough scenario inducing sufficient pain to start the conversation on how to address it in a future release. Most likely, this would imply re-assessing the modeling strategy we're currently using to store the form state. (Possibly related to #104) It would be great if there were some way to build the form model outside of the build() method, in initState() for example. I can work around this by writing my own form model classes that do the validation but I don't think that should be necessary because it makes me re-implement form validation on my own, rather than just using the one already built into this package.

@deandreamatias deandreamatias added the enhancement New feature or request label Jun 9, 2022
@deandreamatias
Copy link
Collaborator

Hi @VOIDCRUSHER
Thanks for your extended comment.
This still a problem? Considering the new versions of this package, maybe can control this scenarios better
If not, please add some code or app example to understand better the scenarios and posible solutions

@deandreamatias deandreamatias added the awaiting author response Waiting for author of issue to respond with more info label Jul 21, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Aug 21, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting author response Waiting for author of issue to respond with more info enhancement New feature or request Stale
Projects
None yet
Development

No branches or pull requests

2 participants