unespected error from Datatable script and jquery

unespected error from Datatable script and jquery

arcanisgkarcanisgk Posts: 41Questions: 12Answers: 0

i have a function to clone last row and push into datatable:

but when i goin to add the row #7 i get this error:

Uncaught RangeError: Maximum call stack size exceeded
    at String.replace (<anonymous>)
    at Function.ga.matchesSelector (jquery.min.js:2)
    at Function.r.filter (jquery.min.js:2)
    at e.fn.init.r.fn.<computed> [as children] (jquery.min.js:2)
    at ea (datatables.min.js:18687)
    at ta (datatables.min.js:18715)
    at Ha (datatables.min.js:19250)
    at Z (datatables.min.js:18241)
    at ma (datatables.min.js:19151)
    at Z (datatables.min.js:18245)

Example Function

function AddRemoveFiles() {
    var x = 1;
    //agregar columnas a table formulario p-sis-0170
    $('#plusbtnfile').on("click", function() {
        var x = $("#Add-Files tr").length + 1;
        var limit = $("#Add-Files").attr('data-limit') || 10;
        var TableTemp = $("#Add-Files").parents('table').eq(0);
        var classList = TableTemp.attr('class');
        if ($("#Add-Files tr").length <= limit) {
            window.Select2Des();
            var $clone = $("#Add-Files tr:last").clone();
            $clone.find("select").each(function() {
                var Cattr = $(this).attr('name');
                Cattr = Cattr.replace(/[0-9]+$/, '');
                $(this).attr('name', Cattr + x);
                $(this).prop('id', Cattr + x);
            });
            $clone.find("input:file").each(function() {
                $(this).attr('id', 'i_file_' + x);
                $(this).attr('name', 'i_file_' + x);
                $(this).val('');
            });
            $clone.find(':input[type="number"]').each(function() {
                var attrd = $(this).attr('data-clean');
                var Cattr = $(this).attr('name');
                Cattr = Cattr.replace(/[0-9]+$/, '');
                $(this).attr('name', Cattr + x);
                $(this).prop('id', Cattr + x);
                if (typeof attrd === "undefined" || attrd !== 'false') {
                    $(this).val('');
                }
            });
            $clone.find("input:text").each(function() {
                var attrd = $(this).attr('data-clean');
                var Cattr = $(this).attr('name');
                if (typeof Cattr !== "undefined") {
                    Cattr = Cattr.replace(/[0-9]+$/, '');
                }
                $(this).attr('name', Cattr + x);
                $(this).prop('id', Cattr + x);
                if (typeof attrd === "undefined" || attrd !== 'false') {
                    $(this).val('');
                }
                if (~Cattr.indexOf("i_txt_line_")) {
                    $(this).val(x);
                }
            });
            $clone.find("input[type=checkbox],input[type=hidden]").each(function() {
                var Cattr = $(this).attr('name');
                if (typeof Cattr !== "undefined") {
                    Cattr = Cattr.replace(/[0-9]+$/, '');
                }
                $(this).attr('name', Cattr + x);
                $(this).prop('id', Cattr + x);
            });
            $clone.find("button[data-target]").each(function() {
                $(this).attr('data-target', '#modal-info-i_file_' + x);
            });
            if (TableTemp.hasClass("DataTableHelper11")) {
                var table = TableTemp.DataTable();
                table.row.add($($clone)).draw();
            } else {
                $("#Add-Files").append($clone);
            }
            var $doc_count = $('[name="i_txt_doc_count"]');
            if (typeof $doc_count !== "undefined") {
                if ($doc_count.length > 0) {
                    $doc_count.val(x);
                }
            }
            window.Select2();
            window.LoadDatepickersAV();
            window.ToolTipsHandle();
        } else {
            alert("Error: no puede Agregar mas Archivos al Sistema");
        }
    });
    $('#minusbtnfile').on("click", function() {
        if ($("#Add-Files tr").length != 1) {
            var z = $("#Add-Files tr").length - 1;
            $("#Add-Files tr:last-child").remove();
            x = x - 1;
            var $doc_count = $('[name="i_txt_doc_count"]');
            if (typeof $doc_count !== "undefined") {
                if ($doc_count.length > 0) {
                    $doc_count.val(z);
                }
            }
        } else {
            alert("Error: no puede Quitar todos los Archivos Adjuntos");
        }
    });
}

Answers

  • arcanisgkarcanisgk Posts: 41Questions: 12Answers: 0

    i have find the error testing and comment line per line:

    when and error cour when i try to inicialice datatable and draw:

    $('#plusbtnfile').on("click", function() {
        var $clone = $("#Add-Files tr:last").clone();
        $clone.find("select").each(function() {
            var Cattr = $(this).attr('name');
            Cattr = Cattr.replace(/[0-9]+$/, '');
            $(this).attr('name', Cattr + x);
            $(this).prop('id', Cattr + x);
        });
        //this lines:
        var TableTemp = $("#Add-Files").closest('table');
        var table = TableTemp.DataTable();    
        table.row.add($clone).draw();
    });
    
  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.