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

Question

Question

Remove all but the first row in a form's table

asked on December 1, 2017

Good morning,

I'm trying to find a way to remove all but the first row in a table when a radio button is clicked. Let's say that I have radio button Yes/No and if I click Yes, a table is populated from a Lookup Rule with various values. If I click No I'd like to remove all the rows in the table, except for the first one.

I'm trying to work with $('.some input').change(); and other quick workarounds, but was wondering if there is simply a quicker method to empty all the rows, but the first one. 

Will keep trying.

Thank you,

Raul Gonzalez

tables.PNG
tables.PNG (6.81 KB)
0 0

Answer

SELECTED ANSWER
replied on December 3, 2017

Hey,

Try this.

$(document).ready(function() {
  $('.radiobtn').change(function() {
    if($('.radiobtn input:checked').val() == "No")
    {
      $(".tbl tr").slice(2).find('.cf-table-delete').click(); 
    }
    else
    {
      $('.autofill').click();
    }
  });
})

Just give your table the css class tbl and your radio button the class radiobtn.

 

Hopefully this will get you started.

1 0
replied on December 4, 2017

Thanks Aaron, this does what I needed.

 

Thank you,

Raul Gonzalez

0 0

Replies

replied on December 7, 2017

Hey,

Collections arnt stored in a table so tr wont be any use here. probable want to do something like:

$(".cf-collection>div.form-q").slice(2).find('.cf-collection-delete').click();

Cant test it at the moment but that's what it should be in theory.

Hope that helps.

1 0
replied on December 7, 2017

Good morning Aaron,

I'm trying to do the same thing, but now with a collection. I have the following but can't make it work. What should I try?

 

$(document).ready(function() {
  $('.radiobtn').change(function() {
    if($('.radiobtn input:checked').val() == "No")
    {
      $(".collectionClassName tr").slice(2).find('.cf-collection-delete').click(); 
    }
    else
    {
      $('.autofill').click();
    }
  });
})

 

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

Sign in to reply to this post.