Simplify a JS function.

This commit is contained in:
Alexis Métaireau 2018-08-05 19:09:08 +02:00
parent 67de8c3b35
commit 292397aff7
2 changed files with 8 additions and 19 deletions

View file

@ -1,18 +1,7 @@
// Add scripts to select all or non of the checkboxes in the add_bill form
function selectall()
{
// Utility to select all or none of the checkboxes in the add_bill form.
function selectCheckboxes(value){
var els = document.getElementsByName('payed_for');
for(var i =0;i<els.length;i++)
{
els[i].checked=true;
for(var i = 0; i < els.length; i++){
els[i].checked = value;
}
}
function selectnone()
{
var els = document.getElementsByName('payed_for');
for(var i =0;i<els.length;i++)
{
els[i].checked=false;
}
}
}

View file

@ -100,7 +100,7 @@
<label class="col-3" for="payed_for">{{ _("For whom?") }}</label>
<div class="controls col-9">
<ul id="payed_for" class="inputs-list">
<p><a href="#" id="selectall" onclick="selectall()">{{ _("Select all") }}</a> | <a href="#" id="selectnone" onclick="selectnone()">{{_("Select none")}}</a></p>
<p><a href="#" id="selectall" onclick="selectCheckboxes(true)">{{ _("Select all") }}</a> | <a href="#" id="selectnone" onclick="selectCheckboxes(false)">{{_("Select none")}}</a></p>
{% for key, value, checked in form.payed_for.iter_choices() %}
<p class="form-check"><label for="payed_for-{{key}}" class="form-check-label"><input name="payed_for" type="checkbox" {% if checked %}checked{% endif %} class="form-check-input" value="{{key}}" id="payed_for-{{key}}"/><span>{{value}}</span></label></p>
{% endfor %}