Last active
March 6, 2018 18:23
-
-
Save Tom32i/6599990 to your computer and use it in GitHub Desktop.
A simple way of automatically render Add and Delete buttons to collections through form theming.
You just need to implement the "addPrototype(form_id)" Javascript function. #Symfony2 #Form #Collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "form_div_layout.html.twig" %} | |
{% block form_row %} | |
{% spaceless %} | |
<div> | |
{{ form_label(form) }} | |
{{ form_errors(form) }} | |
{{ form_widget(form) }} | |
{% if form.parent.vars.allow_delete|default(false) %} | |
<button type="button" onclick="this.parentElement.parentElement.removeChild(this.parentElement)"> | |
× | |
</button> | |
{% endif %} | |
</div> | |
{% endspaceless %} | |
{% endblock form_row %} | |
{% block collection_widget %} | |
{% spaceless %} | |
{{ parent() }} | |
{% if allow_add|default(false) %} | |
<button type="button" onclick="addPrototype('{{ id }}')"> | |
+ | |
</button> | |
{% endif %} | |
{% endspaceless %} | |
{% endblock collection_widget %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment