You are viewing limited content. For full access, please sign in.

Question

Question

Forms - run javascript when row is deleted

asked on February 18, 2017 Show version history
$('.form-del-field').click(function(){ MyFunction(); return false; });

Trying to update the form when a user deletes a row from a table.

I am using some code recommended from the community for executing a function when a hyperlink is clicked. Most recommend to include the function name in the hyperlink code but that is impossible since we have no access. This was the only other recommendation I could find. It does not appear to work though.

I found the class for the hyperlink called form-del-field but the function doesn't run.

1 0

Replies

replied on February 18, 2017 Show version history

Try this. 

$('.tableClassName').on('click','.form-del-field', function () { 
  alert('clicked!');
});

 

3 0
replied on February 19, 2017

For some reason it is just not working for me. Further more I just found out that when you click the X it doesn't delete the row, it just hides it. It doesn't actually delete it unless you make another change in the table. So even if I detect that they deleted a row, I can't see what they deleted since it is still there. Not sure how I am going to handle this one.

0 0
replied on February 20, 2017

What version of Forms are you using?

Do your other functions on the form run?

1 0
replied on February 23, 2017

Running 10.2 at the moment. All other javascript functions are running. I did replace the tableClassName with the table class when testing. The real problem is with the data not deleting though at this point.

Here was how I determined that was happening.

I created a button that called my function to output the data from each row in the table. Then I populated 2 rows of data, deleted the second row, and immediately clicked the button. The javascript found 2 rows of data. Then I clicked into the field within the first row and clicked the button again, the javascript found only 1 row of data. When you click the X button, the data is not removed unless you click somewhere else within the table afterwards.

0 0
replied on August 13, 2021

Thanks, that was exactly what I was looking for, works for me!

0 0
replied on February 20, 2017

Hi Chad,

Matthew's code was working as expected for me. To use that code, you need to have 'tableClassName' as css class on table, and place the code inside a document ready block.

And for the other issue, when I clicked the remove row button, the row was removed from page, not hidden. Can you check if your issue persists without custom JavaScript?

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.