CraueFormFlowBundle
CraueFormFlowBundle copied to clipboard
Support for collection FormType
I have been busy with the bundle the last few days, and I'm positively suprised about the amount of flexibility this bundle adds to the regular Symfony form component.
An extra feature that could be added, is extended support for the collection
field type. This can be best explained based on your example about the car. It would be nice if steps could be repeated, based on for example the input of a previous step.
- Give in the amount of wheels that a car has
- Repeat the step to specify the wheels, based on the amount of the previous step
My own use-case is the need of a repeatable step, which actually is not dependent on previous input. I'm building a flow where users can give in their working experience, so probably I will also need some extra buttons like save + add extra
.
This in my opinion could be something that can be arranged in the FormFlow
. This also is something that is related to #67
It's hard to imagine how this would look like. I can think of two approaches:
- A) One step is added several times (dynamically). This would result in inconsistent validation groups, as they are generated using step numbers.
- B) One step is repeated several times, while the step number stays the same. How would you go back, either within the loop or to the real previous step? This seems confusing from a user's POV.
But I also don't understand the example. Could you try explaining this in more detail?
I agree on the fact that step numbers should not change, in case this will get implemented. To elaborate a bit more on my usecase: the user should be able to repeat a single step as many times he wants. So a example flow could look like:
- Step 1: General info
- Step 2: Add education (save + add another education)
- Step 2: Add education (save + add another education)
- Step 2: Add education (save + add another education)
- Step 2: Add education (save + go to next step)
- Step 3: Confirmation page
To answer your questions:
A) The validation groups should stay the same
B) Good point, I think the "previous step" button should always result in the previous step. How do collection specific buttons sound to you? I think the following buttons are needed: save + add new
, back to previous
, where the latter is hidden or inactive in case there are no entities in the collection yet.
@Rvanlaak Using the collection type it is already possible to achieve what you want with a single step.
I'd agree with the OP's intention being valid. I have the same issue... it stems from having nested, repeatable entities that need to be filled out. While, it definitely is POSSIBLE to add the "sub-entities" via a collection field, it then relies heavily on javascript to provide a clean presentation when you have over 20 fields per "sub-form". My example is as follows:
- Step 1: Select patient
- Step 2: Fill diagnosis information and one or multiple drug regimens
- Step 3 (repeatable): For each drug regimen selected in step 2, provide individual details (dates, dosage, etc) for each drug application.
- Step 4: Confirm and save
It gets even more complicated by the fact that each step 3 can have one nested sub-regimen of drugs (a "cocktail" of sorts). While this is all possible via collections (and a "polycollection" extension), it definitely is not "clean".
I always use TurboTax as an example of multi-step forms. This would be akin to adding multiple W-2 forms per tax return in my mind.
*edit: Perhaps it's possible to trigger a secondary instance of your form flow from inside the original flow?
Hi, @nerdsrescueme , @rvanlaak : did you managed to do that?
I'm in the same situation...
A solution can be to dynamically add new steps when a user click on a specific button or based on a prevoius field value (maybe a checkbox...)
I'm having trouble to understand how this works too. I have entities with OneToMany relations and the example provided seems not to explain this.