简体   繁体   English

自定义布局到sfWidgetFormDoctrineChoice禁用复选框

[英]Customizing layout to sfWidgetFormDoctrineChoice disable checkbox

Good morning, 早上好,

In Symfony 1.4, 在Symfony 1.4中,
I tried to do what is explained here : Customizing layout to sfWidgetFormDoctrineChoice 我尝试执行此处说明的操作:将布局自定义为sfWidgetFormDoctrineChoice
But it doesn't work. 但这是行不通的。 Instead of adding a thumbnail, I just want to hide the <li> before the input, and in some condition disable/hide the checkbox input but show the label anyway . 除了添加缩略图之外, 我只想在输入之前隐藏<li> ,并在某些情况下禁用/隐藏复选框输入,但仍然显示标签
When I add the renderer without argument, I get this error : 当我添加不带参数的渲染器时,出现以下错误:
sfWidgetFormMySelectCheckbox requires the following options: 'choices'.

Here is my formatter code : 这是我的格式化程序代码:

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);
  }
}

And now the form where I call it : 现在是我称之为的表格:

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

Thanks for your help ! 谢谢你的帮助 !

According to the docs you have to pass the choices option to the renderer object. 根据文档,您必须将choices选项传递给renderer对象。 Try something like this: 尝试这样的事情:

$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'))
)));

So basically you want the renderer object get the choices from the parent widget. 因此,基本上,您希望渲染器对象从父窗口小部件中获得选择。 To do that you have to pass a sfCallable object which takes an array as the first argument in which you pass the instance of your parent widget and the name of the function getChoices . 为此,您必须传递一个sfCallable对象,该对象将array作为第一个参数,并在其中传递父窗口小部件的实例和函数getChoices的名称。

Remember also that the expanded option is not used when you override the renderer . 还要记住,当您覆盖renderer时,不会使用expanded选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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