Stub for choice selection

This commit is contained in:
Midgard 2020-03-03 16:21:01 +01:00
parent e434aad3b8
commit f60c1d180c
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -54,24 +54,26 @@
</div>
<input type="hidden" name="form_for_dish" value="{{ dish.id }}" />
{% if dish and dish.choices %}
{% for (choice_type, choice) in dish.choices %}
<div class="form-group select2-container select2">
<label class="control-label" for="choice_{{ choice.id }}">{{ choice.name }}</label><br/>
<select
{{ "multiple=multiple" if choice_type=="multi_choice" else "required=required" }}
name="choice_{{ choice.id }}"
class="form-control select">
{% for option in choice.options %}
<option value="{{ option.id }}"><!--
-->{{ option.name }}{{ ": " + option.price|euro if option.price else "" }}<!--
-->{{ " (" + option.description + ")" if option.description else "" }}<!--
--></option>
{% endfor %}
</select>
</div>
{% endfor %}
{% endif %}
<div id="dish_choices">
{% if dish and dish.choices %}
{% for (choice_type, choice) in dish.choices %}
<div class="form-group select2-container select2">
<label class="control-label" for="choice_{{ choice.id }}">{{ choice.name }}</label><br/>
<select
{{ "multiple=multiple" if choice_type=="multi_choice" else "required=required" }}
name="choice_{{ choice.id }}"
class="form-control select">
{% for option in choice.options %}
<option value="{{ option.id }}"><!--
-->{{ option.name }}{{ ": " + option.price|euro if option.price else "" }}<!--
-->{{ " (" + option.description + ")" if option.description else "" }}<!--
--></option>
{% endfor %}
</select>
</div>
{% endfor %}
{% endif %}
</div>
<div class="form-group {{ 'has-errors' if form.dish_id.errors }}">
{{ form.comment.label(class='control-label') }}<br>
@ -202,5 +204,11 @@
var choice = options[index]
select.val(choice.value).trigger("change")
}
function updateChoices() {
var dish_id = $("#dish_id").val();
$("#dish_choices").html("Choices for " + dish_id);
}
$("#dish_id").on("change", updateChoices);
</script>
{% endblock %}