Reputation: 434
I have a django app that returns a list of table rows into a html table and one of the fields is supposed to be an selector with a set of predefined values and selected value has to be the one provided as a variable from django app. Here's the code:
<table>
<thead>stuff here</thead>
<tbody style="font-size: 10px">
{% for ticket in scope %}
<tr>
<td id="tId" name="tId">{{ ticket.0 }}<input type="checkbox" id="accept" name="accept" value="{{ ticket.0 }}"/> <br />Select</td>
<td hidden><input name="list_{{ ticket.0 }}" value="list_{{ ticket.0 }}"/></td>
<td>
<select id="lvl4" name="lvl4">
<option id="ticket1" value="{{ ticket.1 }}">{{ ticket.1 }}</option>
</select>
</td>
<td>{{ ticket.2 }}</td>
<td>{{ ticket.3 }}</td>
<td>{{ ticket.4 }}</td>
<td>{{ ticket.5 }}</td>
</tr>
{% endfor %}
</tbody>
</table>
Set of available values:
Set of values retrieved from the SQL table:
What I want to achieve with this select field is to select {{ ticket.1 }}
matching option or the "wrong ticket type"
if there is no matching option.
Please let me know if more information is needed. Thank you for your support.
EDIT: Code of the select tag I would like to achieve:
<select id="lvl4" name="lvl4">
<option value="value1">value 1</option>
<option value="value2">value 2</option>
<option value="value3">value 3</option>
<option value="value4">wrong ticket type</option>
</select>
With option value selected that equals the {{ ticket.1 }}
value or "value4"
if no match.
Upvotes: 0
Views: 2162
Reputation: 434
Some comments suggested my question is not clear which I agree it could be the case. Please forgive me, English is not my native language, but I'm trying :)
In the meanwhile a colleague of mine provided me with a solution I was looking for.
And here it is:
<select name="lvl4_{{ ticket.0 }}">
<option {% if ticket.1 == "Run Support" or ticket.1 == "User Support" %}selected {% endif %} disabled>incorrect ticket type</option>
<option {% if ticket.1 == "Change Request" %}selected {% endif %} value="Change Request">Change Request</option>
<option {% if ticket.1 == "Internal Ticket" %}selected {% endif %} value="Internal Ticket">Internal Ticket</option>
<option {% if ticket.1 == "Enhancement Request" %}selected {% endif %} value="Enhancement Request">Enhancement Request</option>
<option {% if ticket.1 == "Technical Request" %}selected {% endif %} value="Technical Request">Technical Request</option>
</select>
Upvotes: 1