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

Question

Question

Forms Lookup - Populate Dropdown with Non-Unique Values

asked on May 27, 2016 Show version history

When populating a dropdown list with all the values in a specific column in a database, the dropdown only includes the unique values from the database. Normally, that's what you want. However, I have a case in which I'd like the dropdown list to include all values, including duplicates, from the database.

The dropdown list that has duplicates is being hidden, so users won't even know it exists. I'm using the values in that dropdown as tooltips for the options in a second dropdown list. The only problem I'm having is that there are about a dozen rows in the database that have identical values. And changing those rows is not possible.

So, I'm hoping there's some kind of class or attribute I can set on the select field that will allow duplicate options to be created during the lookup.

Or if you have a better way of adding tooltips to select options from a database, I'd be willing to try it.

Thanks!

0 0

Replies

replied on June 9, 2016

Just wanted to update this question with the solution we came up with. The solution from Rui above worked. However, because there are over 500 entries in the database, 500 database lookups (along with several others on the same form) makes the form unusable (took a long time to load). So, we created a view that combines the id's and descriptions in the same field (id - description), which makes each one unique. And since the only data we want to have subsequent forms display and that we want workflow to get when it accesses the form data is the id itself, we strip the " - description" part of the option off when the user selects it. The description is dynamically added back to the option if the user changes his/her mind and selects a different option.

Also, since these dropdowns are in a table in which rows can be added, rather than having the lookup run multiple times, I created hidden dropdowns for each and have the lookups populate those. Then I clone the options of each of those to the dropdowns in the table. This also gives me more control on when to call other functions that prepare those fields for use. I don't have to use "setTimeout" to give the database lookup a chance to complete. (That's a problem I'd like to figure out a solution for.) So far, this solution seems to work great.

1 0
replied on May 29, 2016

So you problem is the number of options in the second dropdown list doesn't match the number of options in the hidden dropdown list? Can you share with us how do you add the tooltip for the second dropdown list?

0 0
replied on May 30, 2016

Yes. The first dropdown is populated by a column that contains unique id's. The second dropdown is populated by another column in the same table, but the values in that column aren't all unique. This is an AP vendor table, so the same vendor name could exist multiple times because they may do business with more than one of its locations.

Here's how I'm using the values of the second dropdown (the vendor name) as tooltips. I set a timeout so that the dropdowns can be loaded with the values (10 seconds may be too long, but right now I'm not worried about that - though I'd like to be able to somehow know when the lookups are done populating those fields, rather than use timeouts):

          setTimeout(function() {
            var vendorLength = $('.vendorid select').find('option').length;
            var vendorNums = $('.vendorid select').find('option');
            var vendorDescrip = $('.vendor-descrip select').find('option');
            var descString; 
    
            for ( i=1; i < vendorLength; i++) {  // starting with index 1 because 0 is blank
                 descString = $(vendorDescrip).eq(i).text();
         
                  $(vendorNums).eq(i).attr('title', descString);
            }
            $('.vendorid select').tooltip();
        }, 10000); 
  
 

0 0
replied on May 31, 2016

What about calling lookup individually? First use one of the dropdown option to fill a match field, then wait for lookup to fill the target field, and then use the target field value to update the title of the options, and trigger the next lookup.

Here is the script that works in the above way (need two fields with class "vendor-ID" and "vendor-descrip"):

$(document).ready(function(){
             var vendorDescrip = $('.vendor-descrip input');
             var vendorID=$('.vendor-ID input');
  	     var descString;
             var vendorIDText;
             var index = 1;
  	     var vendorLength = 1;
  
            $('.vendor-descrip input').on('lookup change', function(){              
              descString=vendorDescrip.val();
              if (index < vendorLength)
              {              
                $('.vendorid select').find('option').eq(index).attr('title', descString);
                console.log("des" + descString);              
                index++;
                vendorIDText = $('.vendorid select').find('option').eq(index).text();
                vendorID.val(vendorIDText);vendorID.change();
              }
              console.log(index + "/" + vendorLength);
            }); 

	setTimeout(function() {
             vendorLength = $('.vendorid select').find('option').length;
             vendorIDText = $('.vendorid select').find('option').eq(index).text();
              vendorID.val(vendorIDText);vendorID.change();
              $('.vendorid select').tooltip();
         }, 10000); 
});

 

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

Sign in to reply to this post.