[英]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我在不同的选项卡中有 $form 和一些字段,可以正常工作,我想在表单中添加一个字段
$this->getSubject()->getId()
if this condition is not NULL如果这个条件不是 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):我做了什么,在定义了在所有条件下都应该可见的表单之后,我添加了这部分代码,在选项卡维度中添加字段 url(选项卡维度已经添加到之前的 formmapper 定义中):
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.像这样使用 Tab 如果你想添加分组而不是
With
function。
if($this->getSubject()->getId(),== NULL) { $formMapper ->tab('dimension') ->add('url', null, [ 'required' => false; ]) ->end(); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.