简体   繁体   中英

sonataadmin - add form field at the begining of the ertain existing tab only if condition is true

I have $form and some fields in the different tabs, that works okay, I want to add a field into the form

$this->getSubject()->getId() 

if this condition is not NULL

What I did, after defining form that should be visible in all conditions i added this part of code, to add field url in the tab dimension (tab dimension is already added in previous formmapper definition):

if($this->getSubject()->getId()  !== NULL){
$formMapper
        ->with('tab.dimension')
                ->add(
                'url',
                null,
                [
                    'required' => false,
                ]
            )
->end();
}

But the error i recive is:

New tab was added automatically when you have added field or group. You should close current tab before adding new one OR add tabs before adding groups and fields.

Any help?

use Tab like this If you want to add groupping than use With function.

if($this->getSubject()->getId(),== NULL) { $formMapper ->tab('dimension') ->add('url', null, [ 'required' => false; ]) ->end(); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM