Problems with listing an entity as a checkbox in Symfony2

1

My system has two related tables called material and items_budget . The second table has a form that lists the name of each material in a checkbox, followed by two input , one for its quantity, and another for the price. Here is the code snippet for this:

{% for material in materials %}
    <div class="checkbox">
        <label>
            <input class="itemsbudget_material" type="checkbox" name="cdg_itemsbudget_type[material][]" value="{{ material.id }}"> {{ material.name }} - 
        </label>
        <input class="itemsbudget_quantity" type="text" name="cdg_itemsbudget_type[quantity][]" placeholder="Qtd" size="5"/>x - R$
        <input class="itemsbudget_price_hidden" type="hidden" value="{{ material.price }}"/>
        <input class="itemsbudget_price" type="text" name="cdg_itemsbudget_type[price][]" value="0" size="5" readonly/>
    </div>
{% endfor %}

There is a trigger that triggers when a new data is entered in items_budget , whose function is to subtract from the current amount of the material selected quantity entered in the form field.

Below the items_budget :

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('budget', 'entity', array(
                'class' => 'PanelBundle:Budget',
                'attr' => array(
                    'class' => 'form-control',
                ),
            ))
            ->add('material', 'entity', array(
                'class' => 'PanelBundle:Material',
                'attr' => array(
                    'required' => true,
                ),
            ))
            ->add('quantity', 'number', array(
                'attr' => array(
                    'class' => 'form-control',
                ),
            ))
            ->add('price', 'money', array(
                'attr' => array(
                    'class' => 'form-control',
                ),
            ));
}

The problem is that the trigger function only works correctly with the first record of the material table, with the rest, the quantity field is always NULL. As per the code above, I tried to proceed by placing brackets at the end of the name attribute, but by doing this the form page is only reloaded and no data is entered into items_budget . Is there any other way to list entities in Symfony2? Thanks!

    
asked by anonymous 21.09.2015 / 00:52

0 answers