sfValidatorChoice 不适用于多重选择元素
sfValidatorChoice 不适用于多个选择元素,我的代码
$this->form=new MyTestForm();
$options_array=array("php","python","java");
$widgetSchema["my_select"] =new sfWidgetFormChoice(array('choices' => $options_array,'multiple' => true,'expanded' => true ));
$validatorSchema["my_select"] = new sfValidatorChoice(array("choices" =>array_keys($options_array)));
注意:我还尝试使用 array_keys 并直接将数组传递给 sfValidatorChoice。
当我提交时,它给出了 Invalid
错误(选中时)和 Required
(未选中时)。 参数有错误或者是bug吗?
sfValidatorChoice is not working on multiple select element, my code
$this->form=new MyTestForm();
$options_array=array("php","python","java");
$widgetSchema["my_select"] =new sfWidgetFormChoice(array('choices' => $options_array,'multiple' => true,'expanded' => true ));
$validatorSchema["my_select"] = new sfValidatorChoice(array("choices" =>array_keys($options_array)));
Note: i have also tried using array_keys and by directly passing the array to sfValidatorChoice.
when i submit, it gives me Invalid
error(when checked) and Required
(when unchecked).
is there any error in parameters or is bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要在验证器和小部件中启用“多个”:
要使任何选择可选,您需要将 required 设置为
false
:最后,我不记得如何使用 sfValidatorChoice (已经有一段时间了),但我认为最好使值可读,所以我会这样做:
我不确定这会解决问题,但它可能会解决问题。
Firstly, you need to enable "multiple" in the validator as well as the widget:
To make having any selection optional, you need to set required to
false
:Finally, I can't exactly remember how to use sfValidatorChoice (it's been a while), but I think it's best to make the values readable, so I'd do:
I'm not certain this will fix the problem, but it may well do.