javascriptcloneoracle-apextabular-form

Clone Row (copy records) in Oracle Apex is not working


<script type="text/javascript">
    function fn_CloneRow(pThis) {
        $(pThis).parent().parent().clone().appendTo($(pThis).parent().parent().parent());
    }

With the use of above code I am able to clone clicked rows in a tabular form to the bottom of the table, but I am unable store them. When I change values of cloned rows, the original row is updated instead of adding a new row when the page is submitted.


Solution

  • That is because in cloning the row you also clone the element containing the primary key. From the top of my head, do this with the following elements:

    You can further improve your code by not doing parent().parent()... and instead simply look up the closest tr or table by using .closest(...)

    var newRow = $(pThis).closest('tr').clone();
    $('input[name=f01]', newRow).val(""); //input with PK value -- make sure this matches your situation!!!
    $('input[name=frowid]', newRow).val(""); //or if the form works with rowid, use this
    $('input[name=fcs]', newRow).val(""); //clear the checksum
    $('input[name=fcud]', newRow).val("C"); //set the record status
    newRow.appendTo($(pThis).closest('table')); //finally, append the row to the table