Question

I work with Symfony 1.4 and Bootstrap. I have a problem formatting list of checkboxes. The text of each checkboxes appears with a line break regarding its checkbox.

Symfony generates this HTML code to each checkbox:

<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>

For Bootstrap display correctly each checkboxes, I need Symfony generate the following code:

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

How I can get this?

Was it helpful?

Solution 2

I changed the approach to solve the problem and decided to use jQuery. I proceeded to create

<div id="checkbox_emisores"> 

Then en _form.php would look like this:

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

Here the function to replace tags for checkboxes generated by Symfony 1.4 by the tag you need Bootstrap. I adapted the function as shown here:

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

OTHER TIPS

On your form class:

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

And try to configure form decorators (sfWidgetFormSchemaFormatter)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top