我想要求集合中的所有复选框
我的代码如下所示:
$this->widgetSchema['consent_confirmation'] = new sfWidgetFormSelectCheckbox(
array(
'choices' => Doctrine_Core::getTable('MyTable')->getOptions(),
)
); 更新:
我的验证如下:
$this->validatorSchema['consent_confirmation'] = new sfValidatorChoice(array(
'choices' => array(Doctrine_Core::getTable('MyTable')->getOptions()),
'multiple' => true,
'required' => true
)); 如果没有全部检查,我如何使其返回“必需”,如果它们都被检查了,如何使其有效?
发布于 2013-11-10 12:43:46
我的symfony 1.*内存在这一点上非常模糊,但我认为您需要在validatorSchema中添加一条规则来处理这个小部件的验证。
根据验证附录,您需要的验证器是sfValidatorChoice。
这个小部件有许多选项,包括:
假设您有两个选项,并且您希望强制选择这两个选项,我猜您可能需要将以下内容添加到表单的configure()方法中:
public function configure()
{
$this->widgetSchema['consent_confirmation'] = new sfWidgetFormSelectCheckbox(array(
'choices' => array(
'1' => 'Yes I agree to #1',
'2' => 'Yes I agree to #2',
)),
);
$this->validatorSchema['consent_confirmation'] = new sfValidatorChoice(array(
'multiple' => true,
'min' => 2,
'max' => 2,
));
}类似这样的事情--老实说,我不确定分配给validatorSchema的是什么,可能会有类似于addValidator()或setValidator()方法的东西。编辑:我认为添加了一些帮助方法,但其中一些方法可能是1.4特定的。不管是哪种方式,上面的作业都应该有效..。
希望这会有所帮助:)
https://stackoverflow.com/questions/19889014
复制相似问题