Open agemmell opened 10 years ago
Its likely that you've just encountered the fact that we havent included any templates to render the form type.
The trouble is when you're using a polycollection you're going to need to customise the layout regardless of what default templates we might provide.
An example for a polycollection template in one of our apps below. It should be noted that this example comes from the original app where the Polycollection was conceived and we've moved on slightly and started to use the collections.js provided by this bundle that requires slightly different class names.
I hope this gives you a starting point, and if you have any time we'd appreciate assistance in creating the doc for the next steps of the Polycollection.
{# In the main form body, render the polycollection #}
{% block body %}
{# ... #}
<div class="row">
<div class="span12">
{{ form_row(form.lines) }}
</div>
</div>
{# ... #}
{% endblock body %}
{# We then overwrite the polycollection row - you'll notice that we're specifically rendering each prototype manually #}
{% block infinite_form_polycollection_row %}
<table class="collection table">
<thead>
<tr>
<tr>
<td colspan="5">
{% set line = attribute(form.vars.prototypes, 'ibms_invoice_line') %}
<a class="add_item btn btn-primary line_ibms_invoice_line pull-right" data-prototype="{{ form_row(line) | escape }}" href="#" style="margin-bottom: 0;"><i class="icon-plus icon-white"></i> Add Invoice Line</a>
{% set line = attribute(form.vars.prototypes, 'ibms_invoice_part_line') %}
<a class="part_search btn btn-primary line_ibms_invoice_part_line pull-right select-event" data-select="part" data-prototype="{{ form_row(line) | escape }}" href="#" style="margin-bottom: 0;"><i class="icon-plus icon-white"></i> <u>S</u>earch for Part</a>
<tr>
<th class="thincontrol">
<th>Description
<th class="span2 right">Quantity
<th class="span2">Unit Price
<th class="span2">$ Total
{{ block('lines_footer') }}
<tbody class="items">
{{ form_widget(form) }}
</table>
{% endblock infinite_form_polycollection_row %}
{# We then need to customise the form template for each of the different child types, only showing one here #}
{% block ibms_invoice_line_row %}
<tr class="item line">
{% set line = form.vars.value %}
<td class="thincontrol">
{% if form._type is defined %}{{ form_widget(form._type) }}{% endif %}
<a class="remove_item btn btn-danger" href="#"><i class="icon-minus icon-white"></i></a>
</td>
<td class="{% if form.description is invalid %} control-group error{% endif %}">
{{ form_widget(form.description, { 'attr': { 'class': 'fullwidth', placeholder: 'Service description' } }) }}
</td>
<td class="right{% if form.quantity is invalid %} control-group error{% endif %}">
{{ form_widget(form.quantity, { 'attr': { 'class': 'span1 quantity' } }) }}
</td>
<td class="{% if form.amount is invalid %} control-group error{% endif %}">
{{ form_widget(form.amount, { 'attr': { 'class': 'input-small price' } }) }}
</td>
<td>$ <span class="total">{{ line.total | default(null) | dough_currency | number_format(2) }}</span></td>
{% endblock ibms_invoice_line_row %}
Ah, makes sense! I did wonder why there weren't any in when I poked around inside it.
Thanks for this. I've been struggling with a solution for this kind of "poycollection" form issue for several days now. To be honest, I didn't expect you to reply so quickly (thank you) so I'm attempting another solution. If that doesn't work I'll circle back.
Despite my efforts I have not managed to successfully use the infinite_form_polycollection. Since the documentation is incomplete I imagine that at least someone has used successfully. I have seen many code snippets but some people publish the forms and other the views, in some place are using PolyCollection and other the Collection Helper. Would it be too much trouble for anyone who has make it work all the components, in replacement of documentation publish a simple example where everything works as it should? At least the three forms and a view for the same scenario?.
I wholeheartedly second what abdielcs said. This is too good to lack proper documentation.
Hi @merk, I am trying to get your PolyCollection working but it doesn't seem to be fully realised.
I followed your instructions (as far as they went). I have a base class with two child classes. Both of these have FormTypes with services. I added their service names to the "infinite_form_polycollection" form field. The rest of the form appears to render properly but there are no add/delete buttons near where the collection should be so I can't seem to do anything.
Is this still a work in progress or should it work?