簡體   English   中英

自定義布局到sfWidgetFormDoctrineChoice禁用復選框

[英]Customizing layout to sfWidgetFormDoctrineChoice disable checkbox

早上好,

在Symfony 1.4中,
我嘗試執行此處說明的操作:將布局自定義為sfWidgetFormDoctrineChoice
但這是行不通的。 除了添加縮略圖之外, 我只想在輸入之前隱藏<li> ,並在某些情況下禁用/隱藏復選框輸入,但仍然顯示標簽
當我添加不帶參數的渲染器時,出現以下錯誤:
sfWidgetFormMySelectCheckbox requires the following options: 'choices'.

這是我的格式化程序代碼:

class sfWidgetFormMySelectCheckbox extends sfWidgetFormSelectCheckbox
{
  public function configure($options = array(), $arguments = array())
  {
    parent::configure($options, $arguments);
  }

  protected function formatChoices($name, $value, $choices, $attributes)
  {
    .....

      // new
      $inputs[$id] = array(
        'input' => sprintf('| test | %s',
          $this->renderTag('input', array_merge($baseAttributes, $attributes))
        ),
        'label' => $this->renderContentTag('label', self::escapeOnce($option), array('for' => $id)),
      );
    }

    return call_user_func($this->getOption('formatter'), $this, $inputs);
  }
}

現在是我稱之為的表格:

$this->setWidget('aaa', new sfWidgetFormDoctrineChoice(array(
    'model' => 'Aaa',
    'expanded' => true,
    'multiple' => true,
    'add_empty' => false,
    'query' => $query,
    'renderer' => new sfWidgetFormMySelectCheckbox()
  )));

謝謝你的幫助 !

根據文檔,您必須將choices選項傳遞給renderer對象。 嘗試這樣的事情:

$this->setWidget('aaa', new sfWidgetFormDoctrineChoice(array(
    'model' => 'Aaa',
    'expanded' => true,
    'multiple' => true,
    'add_empty' => false,
    'query' => $query,
)));

$this->widgetSchema['aaa']->setOption('renderer', new sfWidgetFormMySelectCheckbox(array(
    'choices' => new sfCallable(array($this->widgetSchema['aaa'], 'getChoices'))
)));

因此,基本上,您希望渲染器對象從父窗口小部件中獲得選擇。 為此,您必須傳遞一個sfCallable對象,該對象將array作為第一個參數,並在其中傳遞父窗口小部件的實例和函數getChoices的名稱。

還要記住,當您覆蓋renderer時,不會使用expanded選項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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