2013-10-21 33 views
0

我使用Symfony 1.4和Bootstrap。我有一個問題格式化複選框列表。每個複選框的文本都會顯示關於其複選框的換行符。正確Symfony 1.4和Bootstrap。如何像Bootstrap一樣格式化複選框列表?

<li><input name="mensajes[receptores_list][]" type="checkbox" value="5" id="mensajes_receptores_list_5" /><label for="mensajes_receptores_list_5">Carlos (Admin)</label></li> 

對於引導顯示每個複選框,我需要的Symfony生成下面的代碼:

Symfony的生成HTML代碼到每個複選框

<label class="checkbox"> 
<input name="mensajes[receptores_list][]" type="checkbox" value="5" id="mensajes_receptores_list_5" /> Carlos (Admin) 
</label> 

如何我能得到這個?

回答

0

我改變了方法來解決這個問題,並決定使用jQuery。我開始創建

<div id="checkbox_emisores"> 

然後連接_form.php這個應該是這樣的:

<div id="checkbox_emisores"> 
      <?php echo $form['receptores_list']->renderError() ?> 
      <?php echo $form['receptores_list'] ?> 
</div> 

這裏的功能,以取代由你需要引導標記由Symfony的1.4生成的複選框的標籤。 我適應如下所示的功能:

jQuery : A simple tag replacement

$(document).ready(function(){ 

$.ajaxSetup ({ 
     cache: false  
    }); 
// First delete the label generated by symfony 
    $("#checkbox_emisores").find('label').each(function(index) { 
var htmlStr = $(this).html(); 
$(this).replaceWith(htmlStr); 
}); 
//Then replace the symfony <li> with <label generated class='checkbox'> as needed in Bootstrap 
    $("#checkbox_emisores").find('li').each(function(index) { 
var htmlStr = $(this).html(); 
$(this).replaceWith("<label class='checkbox'>"+htmlStr+"</label>"); 
}); 
    }); 
0

在你的窗體類:

$this->widgetSchema['receptores_list']->setAttribute('class', 'checkbox'); 

並嘗試配置表單裝飾(sfWidgetFormSchemaFormatter)

+0

選項 '的setAttribute(' 類, '複選框')」不,因爲我需要工作。 Symfony放置該屬性,但不是每個複選框,因爲我需要。我試圖'sfWidgetFormSchemaFormatter',但都沒有達到預期的結果。 –