Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit Entity with multiple Addresses in the same Symfony2 twig
    primarykey
    data
    text
    <p>I have an Entity which represents an Instituion. As so, This Institution has multiple addresses (Adress Entity) each one with Street, Postal code, etc.</p> <p>The thing is: I have a twig which shows everything about the institution, including a table of addresses where the institution is placed.</p> <p>All i wanted was to click in one address in the table and have a popup window to edit the address (And then Save button would pass the id of the address to a controller function).</p> <p>What is the best way to do this? The problem here is that i do not have the id of the address until someone clicks on hit. And then i have to fill the form with the correct information.</p> <p>Here is what i have:</p> <p>The table of adresses (in the twig):</p> <pre><code>&lt;tbody&gt; {% for local in locais %} &lt;tr class="odd gradeX"&gt; &lt;td&gt;{{ local.name}}&lt;/td&gt; &lt;td&gt;{{ local.address}}&lt;/td&gt; &lt;td&gt;{{ local.postalCode}}&lt;/td&gt; &lt;td&gt;&lt;a title="Editar" class="label label-info" onclick="editLocal('{{ local.name}}', '{{ local.address}}', '{{ local.postalCode }}' '{{ local.id }}');"&gt; &lt;i class="icon-edit icon-white"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; {% endfor %} &lt;/tbody&gt; </code></pre> <p>Then I have the following javascript function that fills the edit local form:</p> <pre><code>function editLocal(name, address, postalCode, id){ oFormObject = document.forms['editLocal']; oFormObject.elements['fccn_corebundle_localtype_id'].value = id; oFormObject.elements['fccn_corebundle_localtype_name'].value = name; oFormObject.elements['fccn_corebundle_localtype_address'].value = address; oFormObject.elements['fccn_corebundle_localtype_postalCode'].value = codigoPostal; $('#editLocal').modal('show'); }; </code></pre> <p>Everything works ok here! The form pops up with the correct information!</p> <p>Then all i wanted was to get the id and pass it to the controller with the edited information so i can persist the existent local entity!</p> <p>I have the following!</p> <pre><code>&lt;form id="editLocal" class="form-horizontal" action= "{{ path('FccnEduroamEntidadeBundle_editLocal', { 'idLocal': editLocalForm.vars.value.id }) }}" method="post" {{ form_enctype(editLocalForm) }}&gt; {{ form_row(editLocalForm.name) }} {{ form_row(editLocalForm.address) }} {{ form_row(editLocalForm.postalCode) }} {{ form_rest(editLocalForm) }} &lt;div class="form-actions"&gt; &lt;button class="btn" type="submit"&gt;Guardar&lt;/button&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>The problem here is that <strong>editLocalForm.vars.value.id</strong> returns absolutly nothing! But when i check this tag on chrome i have:<br> <code>&lt;input type="hidden" id="fccn_corebundle_localtype_id" name="fccn_corebundle_localtype[id]" value="1"&gt;</code> </p> <p>Is there a better way to do this? Any help would be really appreciated.</p> <p>Thanks.</p> <p>Afonso</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload