自定义布局到sfWidgetFormDoctrineChoice禁用复选框 [英] Customizing layout to sfWidgetFormDoctrineChoice disable checkbox

查看:190
本文介绍了自定义布局到sfWidgetFormDoctrineChoice禁用复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,

在Symfony 1.4中,

我试着做这里解释的内容:将布局自定义为sfWidgetFormDoctrineChoice

但它不起作用。而不是添加缩略图,我只是想在输入之前隐藏< li> ,并且在某些情况下禁用/隐藏复选框输入,但显示标签无论如何

当我添加不带参数的渲染器时,出现此错误:

sfWidgetFormMySelectCheckbox需要以下选项:'choices'。



以下是我的格式化程序代码:

<$ p $公共函数配置($ options = array(),$ arguments = array())
{
父类: class sfWidgetFormMySelectCheckbox extends sfWidgetFormSelectCheckbox
{ :configure($ options,$ arguments);
}

受保护的函数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)),
);
}

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

现在我称之为形式:

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

感谢您的帮助!

解决方案根据文档,您必须将选项选项传递给渲染器对象。尝试类似这样:

  $ this-> setWidget('aaa',new sfWidgetFormDoctrineChoice(array(
'模型'=>'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 对象,该对象将一个数组作为你传递实例的第一个参数您的父窗口小部件和函数名称 getChoices



请记住当您覆盖渲染器时,不会使用扩展选项。

Good morning,

In Symfony 1.4,
I tried to do what is explained here : Customizing layout to 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.
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. 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.

Remember also that the expanded option is not used when you override the renderer.

这篇关于自定义布局到sfWidgetFormDoctrineChoice禁用复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆