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:
- value1
- value2
- value3
- value4 "wrong ticket type"
Set of values retrieved from the SQL table:
- value1
- value2
- value3
- value4 (select the "wrong ticket type" option)
- value5 (select the "wrong ticket type" option)
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.
{{ ticket.1|default:"wrong ticket type" }}?{{ ticket.1 }}and if it's not exists or null, display some default text, you can use template tagdefault.