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

Question

Question

Collections - Display message after lookup

asked on July 24, 2019

Hello,

I am having difficulty implementing a feature request for a form our staff uses.  When they enter an id into a field they want to know if it exists in any of three existing databases and if so display some message with data relating to the database it was found in.

The method i have been trying to use is I have 9 fields, 3 for each data source, with a lookup rule pointed to the id field looking for a match, populating the fields with the necessary data.  I have tried using 3 custom HTML fields to input a message, but if I put javascript inside the custom HTML field to replace the text with data from the lookup fields, it ends up replacing the text in all collections, and somehow makes a second phantom set of fields show up below the current collection.  My attempts to create a javascript function to generate and replace the text have been long and complicated and also haven't worked, as I have tried to trigger the change on the 'lookupcomplete' event, which fires once for every field that has a value looked up, causing it to re-add the same message over again.

Has anyone implemented something like this when working with collections?  Or is there a more obvious way of doing this I am missing?

0 0

Replies

replied on July 24, 2019

First, you need to add something to your lookupcomplete event to look at the triggering field. You can do this with the event.triggerId value, and this will prevent it from acting on every single lookup event.

Then, you could set different processes for different triggers. If you have more than a couple, one way to do it is with a switch. For example,

$(document).on('lookupcomplete', function (event) {
  switch(event.triggerId){
      case 'Field1':
            // do stuff
            break;
      case 'Field2':
            // do stuff
            break;
      case 'Field3':
            // do stuff
            break;
      default:
            break;
  }
});

However, you said you put JavaScript inside the CustomHTML, is that correct? If so, you should not set it up that way, you should only put HTML in there and put the JavaScript in the CSS/JavaScript section of the form designer.

Even if you put JavaScript directly in the CustomHTML, it still applies to the entire page, so you'd only end up creating duplicate processes, which might explain the "phantom" fields.

The reason you're seeing it update all of the collection items is most likely that you're selector is not specifying a specific collection. To prevent all of the custom HTML from being updated at the same time, you'll need to target specific ones and the easiest way to do this would be with an index.

For example, if you give your customHTML the class of "lookupMessage" then you could apply indexing to the JQuery selector to tell it which one to update.

$('.lookupMessage').eq(0) // first one

$('.lookupMessage').eq(1) // second one

and so on.

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

Sign in to reply to this post.