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

Question

Question

Populate Table Row Label with Look Up?

asked on January 21, 2014 Show version history

 Is there a way to populate the Row Label in a table field using a database look up?

0 0

Answer

APPROVED ANSWER
replied on January 22, 2014 Show version history

The tricky part is getting the code to run after the dropdown is populated with the results. Once you do that, you can use something like this to get it working. The following code assumes you have a drop-down (given the filledField class) being populated with values from a lookup, and a table with an Add button (id #q4).

 

You'll probably need to fiddle with this a bit more, but here's a start.

 

$(document).ready(function () {

    function tableAwesome() {

        var resultNumber = $('.filledField option').size();
        for (var i = resultNumber - 1; i > 0; i--) {
            $('#q4').trigger('click');
        }

        for (var i = 1; i <= resultNumber; i++) {
            $('td:contains("Row ' + i + '")').text($('.filledField option:nth-child(' + i + ')').text());
        }
    }


    $('.filledField').change(tableAwesome);

});

Update: The code used to answer this question also applies to this question.

1 0

Replies

replied on January 22, 2014

So, based on the number of results in the lookup, would you expect the number of table rows to adjust to match the number of results? I think it should be possible, but might be a little work.

 

I think it'd work like this:

 

  1. Have the lookup populate a drop-down list
  2. If the list is greater than the number of table rows, add more table rows to balance things out
  3. Iterate through the number of results/rows. Change row one's label to match the first result's value and so on.

 

 

0 0
replied on January 22, 2014

That is correct. We would like the rows to adjust dynamically to the number of results in the lookup.

0 0
APPROVED ANSWER
replied on January 22, 2014 Show version history

The tricky part is getting the code to run after the dropdown is populated with the results. Once you do that, you can use something like this to get it working. The following code assumes you have a drop-down (given the filledField class) being populated with values from a lookup, and a table with an Add button (id #q4).

 

You'll probably need to fiddle with this a bit more, but here's a start.

 

$(document).ready(function () {

    function tableAwesome() {

        var resultNumber = $('.filledField option').size();
        for (var i = resultNumber - 1; i > 0; i--) {
            $('#q4').trigger('click');
        }

        for (var i = 1; i <= resultNumber; i++) {
            $('td:contains("Row ' + i + '")').text($('.filledField option:nth-child(' + i + ')').text());
        }
    }


    $('.filledField').change(tableAwesome);

});

Update: The code used to answer this question also applies to this question.

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

Sign in to reply to this post.