symfony - Conditionally disable validation for embedded form -


I have an embedded form (for address ) which has its own validity for different properties I embed this form in the form of a parent ( person ), and I have a checkbox in the form of a parent who says "does a person have an address?"

When the checkbox is left unchecked, I want to disable all assumptions for the embedded address form. Or, better yet, if I can remove the embedded form completely by joining it will be fine too.

I saw using the verification group, but the usage case did not match my own.

OK, figure it out. When adding AddressType embedded form to my form builder, I simply pass the option of this type of verification group:

  $ builder-> addEventListener (FormEvents: : PRE_SET_DATA, function (FormEvent $ event) {$ form = $ event-> getForm (); $ form- & gt; Add ('address', type new address), array ('label' = & gt; 'Address',' verification (group input) = & gt; function (form interface $ form) {if ($ form-> getParent () -> get ('toggle attender') - & gt; getData ( ) === Incorrect) {Return Array ();} Return Array ('Default');} )));});  

Within the Verification Group Function, one is checked to see if the toggle address is turned off or not to enable the address. If so, return an empty array, by deleting all verification groups, including the "default" one.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -