Added Choose for me button in order
This commit is contained in:
parent
a65540aa06
commit
b324d0a723
1 changed files with 10 additions and 1 deletions
|
@ -32,6 +32,9 @@
|
||||||
<div class="col-md-push-1 col-md-10 darker" id="form">
|
<div class="col-md-push-1 col-md-10 darker" id="form">
|
||||||
<h4>Order:</h4>
|
<h4>Order:</h4>
|
||||||
<form method="post" action="{{ url_for('.order_item_create', id=order.id) }}">
|
<form method="post" action="{{ url_for('.order_item_create', id=order.id) }}">
|
||||||
|
<span class="pull-right">
|
||||||
|
<a class="btn btn-primary" onclick="chooseRandom()">Choose for me</a>
|
||||||
|
</span>
|
||||||
{{ form.csrf_token }}
|
{{ form.csrf_token }}
|
||||||
<div class="form-group select2-container select2 {{ 'has-errors' if form.product_id.errors}}">
|
<div class="form-group select2-container select2 {{ 'has-errors' if form.product_id.errors}}">
|
||||||
{{ form.product_id.label(class='control-label') }}<br>
|
{{ form.product_id.label(class='control-label') }}<br>
|
||||||
|
@ -125,10 +128,16 @@
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
|
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$('.select').select2({
|
var select = $('.select').select2({
|
||||||
'sorter': function(results) {
|
'sorter': function(results) {
|
||||||
return results.sort();
|
return results.sort();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
var options = select[0].options;
|
||||||
|
function chooseRandom() {
|
||||||
|
var index = Math.floor((Math.random() * options.length))
|
||||||
|
var choice = options[index]
|
||||||
|
select.val(choice.value).trigger("change")
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue