- Issue created by @espurnes
- 🇪🇸Spain espurnes
After some digging I was not able to keep the
$form[$child_id]['#access'] = FALSE;
in the MultistepController rebuildForm method and preserve the updated step fields values when going back to the previous step.So, even if it is not the best option, I decided to add a new configuration (use_hidden_flow) at step level to change the
$form[$child_id]['#access'] = FALSE;
by a$form[$child_id]['#attributes']['class'][] = 'hidden';
.If in a form with 3 steps, we enable the use_hidden_flow, all the fields will be rendered (but hidden with css) on each step.
If in step 2, when going back to step 1, the step 2 changes are applied. So, when returning to step 2 the fields do have the previous values.
If the new parameter use_hidden_flow is not enabled, the module continues working as before.
- 🇵🇹Portugal dxvargas
This seems to me like a bug and any solution shouldn't be optional.
The described problem doesn't happen when clicking "Next"? Only when clicking "Back"? What is the difference? Why Next works and Back does not?The patch in #3 is fixes the problem you've described but I'm not sure it's the best option.
I've tested in a entity reference field and in that case it doesn't fix the problem. - 🇵🇹Portugal dxvargas
Ok, I've found a problem when making the "Back" button behave like "Next": the validation will work.
That is a problem. For instance, if the user is going back, this will force the fields to be filled and prevent him from going back otherwise. Not good. - 🇵🇹Portugal dxvargas
I've created a MR with the approach proposed in #3.
But without the change being an option in the configuration.
I don't think that deleting the fields already filled when going back should be an option, never.
Also, I think it complicates the configuration page. The helper text in #3 says: "Hide the other steps fields instead of removing them from the current step.". Someone reading this for the first time wouldn't have a clue about the implications.
There is a good explanation in the code:// Comment about the added use_hidden_flow: // The #access = FALSE is used to do not add the element // on other steps. As a sideeffect, the altered elements // do not persist if the back button is clicked. // To preserve the updated values even when clicking back // the #access = FALSE code is removed and replaced by a // hidden class. All the elements will be there, but will // be hidden to the user. // The use_hidden_flow is a new configuration set at step // level, so the new code will just affect those steps with // the use_hidden_flow set to true, by default is false.
But putting all this explanation in the configuration form would make it too complex.
If this goes just like that it may raise backward compatibility issues in some sites that for some reason test the "#access" property of the fields. So, I propose to merge this in a major release.
If as proposed in #3 the usage of "#access" is configurable, then it won't have backward compatibility issues.
- 🇪🇸Spain espurnes
The solution I’ve submitted in #3 addresses the issue described above. While I acknowledge it might not be the most elegant or optimal fix, I needed to apply a quick solution in a live environment. For that reason, I added the patch with optional settings, ensuring backwards compatibility. This approach allows others in a similar situation to resolve the issue without affecting existing implementations.
I'm glad you are suggesting improvements :). Let's see if any maintainer can check it.
By the way, I’ve noticed there hasn’t been any maintenance activity on this module since March 2024.
- 🇧🇪Belgium herved
I think there are issues with the approach of hiding form elements with CSS.
In our case a textarea element in the form has the hidden class but another class (form-element) applied on it overrides the display so the element is visible on all steps.
Also, doing this means that it completely changes the validation as it requires all required fields in next steps to be filled in while the original implementation of this module does not.entity_form_steps has an interesting take on it, where they preserve values when going back but only keep the valid ones.
See EntityFormSteps::validatePreviousForm. This would involve also changing#limit_validation_errors
andsimple_multistep_register_back
.