Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all,
I wasn't quite ready to push this in with #118, so thought it best to do in a follow-up PR. This essentially adds support for nested forms, which can optionally be executed under a given condition.
Reasoning
Take the example of the Laravel installer. It asks the user which stack they'd like to install: Jetstream, Breeze or nothing. If you think about it, a different set of inputs will be displayed depending on the stack that you select. In the current setup, it isn't possible to do this in a single form; you'd have to separate it out into multiple forms, but doing so would prevent you from reverting through the various form options (ie. once you selected Breeze, you can't go back and select Jetstream without cancelling the command).
Example
Here is an example based on the previously described scenario. The
when
condition passed allows us only run the nested forms if the given closure for each returnstrue
. From the front-end perspective, it feels seamless, as though it were a single, unified form. However, the user can revert back to the first statement at any time. Here is a video showing this example:Screen.Recording.2024-04-17.at.13.33.50.mov
You can see that previous responses are pre-filled, as in standard forms, and that we step through the inputs in logical order.
You can pass the
nested
method either a FormBuilder instance by callingform
directly, or aClosure
if you need access to previous responses from the form.Would love to hear your thoughts! Thanks for all the hard work.
Kind Regards,
Luke