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

Question

Question

Populate field in the table with SQL request

asked on August 15, 2014

 

Hello Everybody,

 

Have a task to populate first column of the table with the data from SQL, then enter data in the next column and finally auto-populate third field with OK if column1 matches column 2

Using different threads I had it running on v 9.0.1 with next code.

 

 

$(document).ready(function () {
    $('#Field8').trigger('change');
    function fillColumn() {
        if ($('tbody tr').length > 1) {
            return;
        } else {
            var resultNumber = $('.filledField').find('option').size();
            for (var i = 1; i < resultNumber; i++){
               k = i + 1;
                $('tr:contains("Req ' + i + '")').find($('.currentValue input')).val($('.filledField').find('option:nth-child(' + k + ')').text());
                $('tr:contains("Req ' + i + '")').find($('.result input')).val('');
              if (i != resultNumber - 1) {
                $('#q10').trigger('click');
                }
               $('.currentValue input').attr('readonly', 'true');
               $('.result input').attr('readonly', 'true');
                $('#q10').hide();
            }
        }
    }
    $('.filledField select').change(fillColumn);
    $('#q8').hide();
//    $('#q14').hide();
   $('.cf-table-block').change(grabVal)
    function grabVal() {
        $('.cf-table-block tbody tr').each(function () {
          if ($(this).find('.fileID input').val() == $(this).find('.currentValue input').val())
            $(this).find('.result input').val('OK');
        });
    }
});

 

However on v 9.1.1 it does not auto-populate first column until value in dropdown field selected (sql request returns 3 values but by some reason dropdown menu has one empty line on top).

Is there something I'm missing?

Thank you,

 

Screen Shot.png
Screen Shot.png (34.32 KB)
0 0

Answer

SELECTED ANSWER
replied on August 19, 2014

I don't remember the exact behavior in version 9.0. However, you can make the selection using jQuery and then trigger the change event:

  $('.filledField select>option:eq(1)').prop('selected', true);
  $('.filledField select').trigger('change');

This will select the second value in the dropdown (index 1), which should be the value that comes after the blank option. Then it will trigger the change event and make that event handler execute.

 

Note that you need to place this code after your  $('.filledField select').change(fillColumn) line. You also need to make sure that, at the time this code executes, the database lookup has already populated the dropdown field with the values - otherwise it won't have anything to select.

2 0

Replies

replied on August 20, 2014

Thank you Sir,

That actually a good suggestion - so far I used the timeout as per this thread:

https://answers.laserfiche.com/questions/55591/Populating-a-table-with-a-sql-lookup-values-via-dropdown-options-without-user-interaction.

Best Regards,

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

Sign in to reply to this post.