question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repeater Item Delete Problem

See original GitHub issue

Hi,

I’m making the calculation in the example I provide at the link.

http://demo.fy.tc/repeater

Every new line does the calculation. However, when I delete a row, it does not perform the calculation again.

` $(document).ready(function () {

    $('#ProposalProducts').repeater({
        isFirstItemUndeletable: true, 
        initEmpty: true,
        show: function () {
            var selfRepeaterItem = this;
            $(selfRepeaterItem).slideDown();            
        },
        hide: function (deleteElement) {
            var selfRepeaterItem = this;
            $(selfRepeaterItem).slideUp(deleteElement);
            
          CalcProducts();
        }        
    });


$('#product_repeat').on('click', function(){

    $('#quantity, #unit_price, #vat, #discount_type, #discount').on("change", function () { 
        CalcProducts();
    });

});

});

function CalcProducts() {



    var repeaterItems_count = $("div[data-repeater-item] > div.product_item");
    var repeaterItems = repeaterItems_count.length;
    
    var products_sub_total = 0;
    var discount = $("#discount").val();
    var discount_type = $("#discount_type").val();
    var products_sub_total_discount = 0;
    var products_total_vat = 0;
    var products_total = 0;

    for (var i = 0; i < repeaterItems; i++) {


        if(typeof $('input[name="products['+i+'][quantity]"]').val() !== 'undefined') {

    
            var quantity = $('input[name="products['+i+'][quantity]"]').val();
            var unit_price = $('input[name="products['+i+'][unit_price]"]').val();
            var vat = $('input[name="products['+i+'][vat]"]').val();

            
            var vat_total = (quantity * unit_price) * vat / 100;
            var sub_total = quantity * unit_price;
            var total =  vat_total + sub_total;
            
            $('input[name="products['+i+'][vat_total]"]').val(vat_total);
            $('input[name="products['+i+'][sub_total]"]').val(sub_total);
            $('input[name="products['+i+'][total]"]').val(total.toFixed(2));

            products_sub_total = products_sub_total + sub_total;
            products_total_vat = products_total_vat + vat_total;
            products_total = products_total + total;                
        }

    }

    if(discount != '' && discount_type != '') {
        if(discount_type == 'rate')
        {
            var products_total_discount_vat = 0;
            var rate_to_discount = products_sub_total * discount / 100;
            var discount_dispersion = rate_to_discount / repeaterItems;

            for (var d = 0; d < repeaterItems; d++) {
                
                if(typeof $('input[name="products['+d+'][quantity]"]').val() !== 'undefined') {
                    
                    var quantity = $('input[name="products['+d+'][quantity]"]').val();
                    var unit_price = $('input[name="products['+d+'][unit_price]"]').val();
                    var vat = $('input[name="products['+d+'][vat]"]').val();
                    
                    products_total_discount_vat = products_total_discount_vat + (((quantity * unit_price) - discount_dispersion) * vat / 100);
                }


            }
            
            products_total = (products_sub_total - rate_to_discount) + products_total_discount_vat;

            document.getElementById('products_sub_total').innerHTML = products_sub_total.toFixed(2);
            document.getElementById('products_sub_total_discount').innerHTML = '(-) '+rate_to_discount.toFixed(2);
            document.getElementById('products_total_vat').innerHTML = products_total_discount_vat.toFixed(2);
            document.getElementById('products_total').innerHTML = products_total.toFixed(2);

        }
        else if(discount_type == 'amount')
        {
            var products_total_discount_vat = 0;
            var discount_dispersion = discount / repeaterItems;

            for (var d = 0; d < repeaterItems; d++) {
                if(typeof $('input[name="products['+d+'][quantity]"]').val() !== 'undefined') {
                    
                    var quantity = $('input[name="products['+d+'][quantity]"]').val();
                    var unit_price = $('input[name="products['+d+'][unit_price]"]').val();
                    var vat = $('input[name="products['+d+'][vat]"]').val();
                    
                    products_total_discount_vat = products_total_discount_vat + (((quantity * unit_price) - discount_dispersion) * vat / 100);
                }

            }
            
            products_total = (products_sub_total - discount) + products_total_discount_vat;

            document.getElementById('products_sub_total').innerHTML = products_sub_total.toFixed(2);
            document.getElementById('products_sub_total_discount').innerHTML = '(-) '+Number(discount).toFixed(2);
            document.getElementById('products_total_vat').innerHTML = products_total_discount_vat.toFixed(2);
            document.getElementById('products_total').innerHTML = products_total.toFixed(2);                  
        }
    }
    else 
    {
        
        document.getElementById('products_sub_total_discount').innerHTML = '';
        document.getElementById('products_sub_total').innerHTML = products_sub_total.toFixed(2);
        document.getElementById('products_total_vat').innerHTML = products_total_vat.toFixed(2);
        document.getElementById('products_total').innerHTML = products_total.toFixed(2);            
    }
    
}    `

Please do help with this.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
gunaysirbudakcommented, Sep 9, 2020

@paulayo93 Check the javascript file you are using. Use the application’s own javascript file.

0reactions
paulayo93commented, Sep 10, 2020

@paulayo93 Check the javascript file you are using. Use the application’s own javascript file.

@gunaysirbudak Do you mean that I should use it from a .JS file instead of writing the code in a script tag? Will that be the case please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deleting from ASP.NET Repeater item - erroneous deleting...?
This way the delete button itself is indicating what ID to delete, as opposed to relying on positional elements in your repeater. Share....
Read more >
Deleting and editing item in a repeater - MSDN - Microsoft
I am learning how to use repeater. I added two links to my repeater, a delete and an edit link. However, when I...
Read more >
[SOLVED] Problem in delete item button in repeater - Wix.com
Hello, please help me with this problem: Why does the button to delete the item from the repeater not work at the first...
Read more >
Not able to delete a repeater item - General Support
Hi I am not able to delete a repeater item This code works $subscriptionpage = $pages->get(1442); ... Even then this is not working...
Read more >
isFirstItemUndeletable doesn't work if you use setList() #92
To start the repeater with some data, using the setList() function, the first element on the repeater is showing the delete button even...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found