Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding new row on a table tbody by cloning the last row with events attached
    primarykey
    data
    text
    <p>I'm trying to clone the last row of a table with input fields that might have events attached, (in this case it's the keyup event). I also change the id's of the input fields to reflect the row where they are, something like:</p> <p>table[0].field1,table[0].field2...table[1].field1...etc.</p> <p>The problem is that I can add a row and it gets the events too, and when i write on the new cloned inputs they do start the events. But only on the first row created. If i create a new one, it will render the row with the inputs correctly but not the events. Here's the method:</p> <pre><code>addRow= function(tableid){ //jquery selector get table tbody with id var table=jQuery('table[id="'+tableid+'"] &gt;tbody'); //get last row containing input fields with tr class hoverTransparente var lastRow=jQuery('table[id="'+tableid+'"] &gt; tbody &gt; tr:last'); //make a clone of the row var clones = lastRow.clone(true); // copy events/children too //get the input fields from the cloned row var clonedInPuts=clones.find('input'); //for each input jQuery(clonedInPuts).each(function (){ //set new input val to empty jQuery(this).val(""); var inputId=jQuery(this).attr('id'); //table id var table=inputId.split("[")[0]; //column id var tableField=inputId.split(".")[1]; var idnumber=inputId.indexOf("[")+1; //convert to number to make addition for new id index var number = Number(inputId.charAt(idnumber))+1; //replace id index with incrementaed value var newId=inputId.replace(inputId.charAt(idnumber),number); //change id for new one jQuery(this).attr('id',newId); //check if this variable exists/is not undefined if(window["elements_"+table+"_"+tableField]){ window["elements_"+table+"_"+tableField].push(jQuery(this).get(0)); } }); clones.appendTo(table); } </code></pre> <p>Any ideas? when i try to debug in chrome the event onkeyup from the domtree of the input element is null but if i select using jquery directly and get the .data('events') method it does return an array with the events attached to the input field. Shouldn't the onkeyup return something different from null?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload