From 31888e33ce54d9962dc2eb40d2366ec758283138 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 30 Mar 2017 13:30:55 -0300 Subject: [PATCH] simpler jquery selection --- kfet/templates/kfet/inventory_create.html | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 7c611eb6..80f9d4c0 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -39,27 +39,27 @@ {{ form.article }} {{ form.name }} - {{ form.box_capacity }} - {{ form.stock_old }} + {{ form.box_capacity }} + {{ form.stock_old }}
- +
-
+
-
+
{{ form.stock_new }}
- + {% endfor %} {{ formset.management_form }} @@ -88,10 +88,14 @@ $(document).ready(function() { $('input[type="number"]').on('input', function() { var $line = $(this).closest('tr'); var box_capacity = +$line.find('.box_capacity').text(); - var box_cellar = +$line.find('.box_cellar input').val(); - var box_bar = +$line.find('.box_bar input').val(); - var misc = +$line.find('.misc input').val(); - $line.find('.stock_new input').val(box_capacity*(box_cellar +box_bar)+misc); + var box_cellar = $line.find('.box_cellar input').val(); + var box_bar = $line.find('.box_bar input').val(); + var misc = $line.find('.misc input').val(); + if (box_cellar || box_bar || misc) + $line.find('.stock_new input').val( + box_capacity*((+box_cellar) +(+box_bar))+(+misc)); + else + $line.find('.stock_new input').val(''); }); /* @@ -107,6 +111,7 @@ $(document).ready(function() { } }); + /** * Websocket */