dependent() works incorrect

dependent() works incorrect

vivalazvivalaz Posts: 10Questions: 6Answers: 0

Using the dependent method, I want to do a recalculation of the sum using AJAX. Since dependent is called 2 times (when the inline editor is opened and when data is being saved), I made a variable-flag, which should send AJAX when the save occurs. However, sometimes in rare cases it works a little earlier. For example, fraht_nal = 5000, fraht_beznal = 8000. When I start deleting a value in fraht_nal, sometimes ajax works earlier, sending for example 50 instead of sending 0 (when the value is completely deleted). I hope I understandably explained, do not tell me why this can happen?
Code:

   function dependentColumns(freightCashCustomer, freightCashNonCustomer, paymentTypeCustomer,
                              freightCashTransporter, freightCashNonTransporter, paymentTypeTransporter,
                              premium, dispatching, paidByClient, field) {
        return $.ajax({
            url: URL + '/controller/cfo/recalc_comission.php',
            method: 'POST',
            dataType: 'json',
            data: {
                'freightCashCustomer': freightCashCustomer,
                'freightCashNonCustomer': freightCashNonCustomer,
                'paymentTypeCustomer': paymentTypeCustomer,

                'freightCashTransporter': freightCashTransporter,
                'freightCashNonTransporter': freightCashNonTransporter,
                'paymentTypeTransporter': paymentTypeTransporter,

                'premium': premium,
                'dispatching': dispatching,

                'paid': paidByClient,

                'field': field
            }
        });
    }

    let dependent_freight_cash_customer_flag = false;
    CFO_EDITOR.dependent('fraht_nal', function(val, data, callback) {
        if(dependent_freight_cash_customer_flag) {
            dependent_freight_cash_customer_flag = false;
            console.log(val);
            console.log(data);

            dependentColumns(val, +data.values.fraht_beznal, +data.values.forma_oplata_zakazchikom,
                +data.values.fraht_nal_perevoz, +data.values.fraht_beznal_prerevoz, +data.values.forma_oplati_perevozu,
                +data.values.sotka_prodazniku_logistu, +data.values.summa_dispetcherskih,
                +data.values.oplacheno_zakazchik, 'fraht_nal')
                .then(function(response) {
                    dependent_freight_cash_customer_flag = false;
                    callback(response);
                    return false;
                });
        } else
            dependent_freight_cash_customer_flag = true;

    });
    let dependent_non_freight_cash_customer_flag = false;
    CFO_EDITOR.dependent('fraht_beznal', function(val, data, callback) {
        if(dependent_non_freight_cash_customer_flag) {
            dependent_non_freight_cash_customer_flag = false;

            dependentColumns(+data.values.fraht_nal, val, +data.values.forma_oplata_zakazchikom,
                +data.values.fraht_nal_perevoz, +data.values.fraht_beznal_prerevoz, +data.values.forma_oplati_perevozu,
                +data.values.sotka_prodazniku_logistu, +data.values.summa_dispetcherskih,
                +data.values.oplacheno_zakazchik, 'fraht_beznal')
                .then(function(response) {
                    dependent_non_freight_cash_customer_flag = false;
                    callback(response);
                    return false;
                });
        } else
            dependent_non_freight_cash_customer_flag = true;

    });

Answers

  • allanallan Posts: 61,933Questions: 1Answers: 10,154 Site admin

    By default dependent() uses the change event, so assuming you are using a text input, it should only trigger again when the input is blurred (usually that happens on submit).

    Are you able to give me a link to the page showing the issue so I can check it out?

    Thanks,
    Allan

  • vivalaz2281vivalaz2281 Posts: 1Questions: 0Answers: 0

    Sorry, but I cant, becaus he is private(

  • allanallan Posts: 61,933Questions: 1Answers: 10,154 Site admin

    Can you able to use http://live.datatables.net to construct a test case so I can debug the issue? Basically I need a way to be able to reproduce the error so I can debug what is going on.

    Thanks,
    Allan

This discussion has been closed.