开发者

sfValidatorChoice not working on multiple selection element

sfValidatorChoice is not working o开发者_开发问答n 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?


Firstly, you need to enable "multiple" in the validator as well as the widget:

"multiple" => true

To make having any selection optional, you need to set required to false:

"required" => 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:

$options_array=array('php'=>'php','python'=>'python','java'=>'java');

I'm not certain this will fix the problem, but it may well do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜