簡體   English   中英

sonataadmin - 僅當條件為真時,才在某些現有選項卡的開頭添加表單字段

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

我在不同的選項卡中有 $form 和一些字段,可以正常工作,我想在表單中添加一個字段

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

如果這個條件不是 NULL

我做了什么,在定義了在所有條件下都應該可見的表單之后,我添加了這部分代碼,在選項卡維度中添加字段 url(選項卡維度已經添加到之前的 formmapper 定義中):

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

但我收到的錯誤是:

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.

有什么幫助嗎?

像這樣使用 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM