Symfony sfWidgetFormSelectDoubleList验证

时间:2011-06-22 10:52:39

标签: php symfony-1.4

sfWidgetFormSelectDoubleList是否有任何验证,当表单无效时,我遇到问题[!isValid()]并使用以前的数据重新加载页面。选项不显示以前选择的值,即使我从下一次选择一些值,我也没有得到任何值。

我的表格是这样的

$this->setWidgets(array(
            'event_title' => new sfWidgetFormInputText(),
            'client_list' => new sfWidgetFormSelectDoubleList(array(
                'choices' => $client,
                'associated_first' => false,
                'label_associated' => '',
                'label_unassociated' => ''
            )),
));

$this->setValidators(array(
            'event_title' => new sfValidatorString(array('required' => true)),  
           ));

//并在我的控制器中

if($form1->isValid()){

               $resource->title = $frmField['event_title'];
               $resource->save();
               //var_dump($frmField);
               return $this->renderPartial('newEvent', array('form1' => $form1));
            } else {
                var_dump($frmField);
                return $this->renderPartial('createEvent', array('form1' => $form1));
            }

无法设置验证器,因为我不知道它。并且完全不知道为什么它在第二次及以后提交时没有任何价值

1 个答案:

答案 0 :(得分:0)

我认为这不是验证问题。永远不会提交所选的值。我想,即使表单有效,也不会保存这些值(您可以在数据库中检查它)。 问题是(我猜)“选定值”选项用值填充,但从不选择此值。该选择中的每个选项不仅应该存在,甚至应该“选中”。该插件缺少该部分。在提交表单时,我通过jquery疯狂地选择了每个选项。 类似的东西:

<script type="text/javascript">
$(document).ready(function() {
    $('#form_html_id').submit(function(e) {
         // You should find this html id for the "selected values" select
         $('#your_entity_client_list option').attr('selected','selected');
         return true;
    });
});
</script>

我希望这个解决方法可以帮到你。 抱歉我的英语不好。