I am totally new to Symfony and Twig; just yesterday I was thrown into a legacy project that uses them.
I have a list, produced by a template loop, of Orders
, each order having a priority
from 1-5.
I want to add a single dropdown Select
to each Order
row
which submits a form updating that Order
's priority
and refreshes the page.
My question is, can I use Symfony's buildForm in conjunction with this architecture? For now I have the following form constructed manually. Is it even possible to build a series of identical forms like this with Twig?:
{% for order in orders %}
<form method="post" action="{{ path('change_priority') }}" style="margin: 0; padding: 0;">
<div class="form-group">
<select name="priority" style="width: 35px; height: 20px;" onchange="this.form.submit()">
<option value="1" {% if order.currentBody.priority == 1 %} selected {% endif %}>1 - Low</option>
<option value="2" {% if order.currentBody.priority == 2 %} selected {% endif %}>2 - Normal</option>
<option value="3" {% if order.currentBody.priority == 3 %} selected {% endif %}>3 - High</option>
<option value="4" {% if order.currentBody.priority == 4 %} selected {% endif %}>4 - Critical</option>
<option value="5" {% if order.currentBody.priority == 5 %} selected {% endif %}>5 - No Priority</option>
</select>
<input name="order_id" value="{{order.serial}}" type="hidden" />
</div>
</form>
{% endfor %}
And here is an image of what I'm after. Changing the priority of any of the Order
row items changes that Order
's priority and then refreshes the page.