You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have had a similar issue with a form for dietary requirements. I have the folllowing fields…
a. Do you have any dietrary requirements (yes/no)?
b. [only if a. = yes] Select your dietary requirement from a list of options;
c. [only if b. is not empty] Collection of fields asking…
What is the reason (choice/intolerance/allergy)?
The problem I had… if I go from a form with…
a. yes;
b. something slected (so c. contains some reason fields for the selection);
c completed reason field(s);
… to…
a. no;
… then field b. disappears, but c. does not… BUT… only when I save the data. If I don't perform a save, field c. also, correctly, disapears. Done a whole load of step debugging, but still cannot fathom why this might be!?
My workaround was to add the following event listener to the form builder that adds the dynamic fields…
->addEventListener(FormEvents::PRE_SUBMIT, function (PreSubmitEvent$event) {
$data = $event->getData();
if (!($data['hasRequirements'] ?? false)) { // <= if a. is 'no'// First I tried this, to remove the collection of reasons, however the previously selected// reasons form still appears, just with empty values…$data['requirements'] = [];
// So I also removed the child form all together…$event->getForm()->remove('requirements');
}
$event->setData($data);
});
I can't seem to get the following to work:
Form Foo with fields:
The above doesn't work though; if I check A, B disappears, but C is still added (or not removed 🤷).
The text was updated successfully, but these errors were encountered: