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