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

Question

Question

Workaround for Lookup populating checkbox in table

asked on October 26, 2017

I need a Lookup to populate a checkbox in a table. Since checkboxes aren't available as Lookup targets, I've added a number field to the table to populate instead (with 1/0). I'm struggling on the JavaScript to check the boxes based on the value in the number field.

 

I assume there's a way to iterate through the table rows, but I haven't been able to find the syntax. Unless there's some way to compare all the values and set the checkboxes at once, using some sort of set/collection based logic?

 

I'm expecting something like this:

  $('.LookupTrigger input').change(function() {
    $(document).on("onloadlookupfinished", function () {
      for each row in .MyTable {
        if ($('.NumberField input').val() == 1) {
          $('.Checkbox input').prop('checked',true);
        }
      }
    });
  });

 

0 0

Replies

replied on October 26, 2017 Show version history

Here's how i managed to do it in one of our form:

 

The "for each row" function should look like something like this

$('#q73 tbody tr').each(function () {

});

 

#q73 is the default selector of my table

 

In this function, to automatically check the boxes, insert this code to validate the value of each specific row and check the boxes:

 

if ($(this).find('.NumberField input').val()=="1") {
                    $(this).find('.checkbox input[value="Value of the checkbox"]').attr('checked', true);
            }

 

Value of the checkbox is the one you can configure in the checkbox option where you can give a value to each choice.

 

Hope I was clear enough to help you a bit.

 

Good luck.

1 0
replied on October 27, 2017

Thanks! That got me going down the right path, though the bit waiting for the lookup wasn't quite right either. Here's what I ended up getting to work:

  $(document).on("lookupcomplete", function(event) {
    if (event.ruleId==944) {
      $('.MyTable tbody tr').each(function() {
        if ($(this).find('.NumberField input').val() == 1) {
          $(this).find('.Checkbox input').attr('checked',true);  //works because I only have one checkbox in this field
        }
      });
    }
  });

 

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

Sign in to reply to this post.