2011-06-22 97 views
1

是否有任何sfWidgetFormSelectDoubleList的驗證,並且當表單無效[!isValid()]時出現問題並使用以前的數據重新加載頁面。選項不顯示先前選擇的值,即使我在下次選擇某個值時我也沒有收到任何值。Symfony sfWidgetFormSelectDoubleList驗證

我的形式是這樣的

$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)); 
      } 

無法設置驗證,因爲我不知道它。並且完全不知道爲什麼它在第二次和第二次提交時沒有任何價值

回答

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> 

我希望這個解決方法可以幫助你。 對不起,我的英語不好。