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

Question

Question

Using Lookup Rules w/ Multiple Collection Entries

asked on October 14, 2020

I've never attempted to use a lookup rule within a collection before, but am running into some issues. Here is the collection I'm currently working with: 

The Department field is a drop down field and when a department is selected, it should populate the Director and Deputy Director/Manager's First Name, Last Name, and Email Address fields based on a lookup rule/table. This occurs correctly when there is only collection entry, but when adding another entry via the "Recognize another employee" button, the Department drop down no longer populates the Director and Deputy Director/Manager fields.

I have two hidden fields as part of the collection that contain default text of "Director" and "Deputy Director". These are used to help pull the correct lines from the lookup table, so when the Department drop down and the Director field (hidden) match, it populates the fields for the Director, and a second rule is set up the same way for the Deputy Director/Manager.

By having two lookup criteria, the autofill button comes into play. I do have some CSS and JavaScript in place however to hide the autofill button and automatically select it, which I think might be the cause of my issue. Here is that code:

CSS:

.autofill {display: none}

JavaScript:

$(document).ready(function() {
  function autofill() {
    $('.autofill').trigger('click');
  } 
  $('.lookupCondition').change(autofill);
});

The Department drop down has also been assigned the CSS class of "lookupCondition".

If anyone has any ideas how to get this to work properly/where I went wrong, I would greatly appreciate it! Thanks!

0 0

Replies

replied on October 16, 2020

When you add a new entry there is no change for the Department dropdown so the autofill function will not be triggered. You may need to trigger the function when add the new entry.

0 0
replied on October 16, 2020

Hi Xiuhong, thanks for the response! Are you saying that even when selecting a value in the Department drop down in the 2nd collection entry, it is not triggering the autofill function?

0 0
replied on October 19, 2020

Yes, it will not, you can refer to https://answers.laserfiche.com/questions/114870/Forms--Making-the-pesky-AutoFill-button-be-Automatic#114879 to develop script that apply to collection.

Also you can use the out of box functionality(uncheck "Show Auto Fill Button", supported since 10.2.1) to hide the auto fill button when the lookup rule has multiple conditions

0 0
replied on October 19, 2020

Ah, that explains it. We are on version 10.2.0.834 unfortunately. I'll see if I can rework the code in that forum discussion to work for my form though. Thank you for passing that along!

0 0
replied on October 22, 2020

I've attempted to repurpose the code in that thread you linked to but unfortunately with my limited JavaScript knowledge, I haven't been able to get it to work. Here's the code I'm using:

function autofill() {  
    $(this).closest("tr").find('button.autofill').trigger('click');
  }
  
  $('.lookuptrigger select').on('change',autofill);
  $('.cf-collection-append').click(function () {
    $('.lookuptrigger select').on('change',autofill);
    $('.cf-collection tr:last').find('button.autofill').trigger('click');
  });

The "Department" dropdown field has the CSS class of "lookuptrigger". Any help would be greatly appreciated. Thanks!

0 0
replied on October 23, 2020

The elements and classes for collection are different, try with following code:

  function autofill() {  
    $(this).closest("ul").find('button.autofill').trigger('click');
  }
  
  $('.lookuptrigger select').on('change',autofill);
  $('.cf-collection-append').click(function () {
    $('.lookuptrigger select').on('change',autofill);
    $('.cf-collection-block ul:last').find('button.autofill').trigger('click');
  });

 

 

0 0
replied on October 23, 2020

Thank you Xiuhong! I appreciate the help! It's still not working though... I've unhidden the two hidden fields which I mentioned in my original post. Here's what it looks like: 

I realize that having the auto fill button next to those hidden fields isn't ideal, but I cannot seem to get it to associate with the Department dropdown. Even still, I tried removing the CSS class of lookupcondition from the Department dropdown and adding it to both of those fields and changing the values in them and the autofill function still didn't automatically occur. 

0 0
replied on October 25, 2020

Can you share the lookup rules configuration?

0 0
replied on October 26, 2020

Sure thing! Here are the two only two rules in place - one to fill the Director fields and one for the Deputy Director fields.

And here is a sample of the table it is pulling data from, minus First and Last names: 

0 0
replied on October 27, 2020

I setup similar lookup rules as yours and the script still works for me(see attached video)

 

If there are multiple results return when select same Department and Title, the value will not be populated in the field.

Maybe your form is more complicated, you can preview the form with Chrome then open the Developer tool and debug the script from Sources tab and adjust your script accordingly. 

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

Sign in to reply to this post.