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

Question

Question

how can i trigger a lookup by hitting enter key

asked on March 10, 2020

I feel this is so primitive...  but I have not found a way to trigger a lookup by entering data and hitting enter.  The end user has to click off the field for the lookup to fire.  So I created a dummy image for them to click on.  I would REALLY love to just use the enter key.  Does anyone have this working?

 

 

Thanks :)

Sue

0 0

Answer

SELECTED ANSWER
replied on March 13, 2020

Try changing #q25 to #Field25. The names that start with #q tend to be a higher level wrapper element, whereas #Field generally designate the actual control.

Notice that I used the words "tend" and "generally".

1 0

Replies

replied on March 10, 2020

You can listen for the keydown event and manually invoke a lookup.

$(document).ready(function() {
  $("#Field64").on('keydown',function(e){
    if(e.keyCode == 13){
      $("#Field64").change();
    }
  });
});

In this example, Field64 is the name of my specific input field. You'll want to get that for your text box. Also, .change() tells Forms to trigger the change event for that field. This causes the lookup to run. The number 13 is the key code that corresponds to the enter key.

6 0
replied on March 13, 2020

Thank you so very much Devin :) :) :)

0 0
replied on March 13, 2020

Not working...  I'm in Forms 10.4.1  

 

$(document).ready(function() {
  $("#q25").on('keydown',function(e){
    if(e.keyCode == 13){
      $("#q25").change();
    }
  });
});

0 0
SELECTED ANSWER
replied on March 13, 2020

Try changing #q25 to #Field25. The names that start with #q tend to be a higher level wrapper element, whereas #Field generally designate the actual control.

Notice that I used the words "tend" and "generally".

1 0
replied on March 17, 2020

That did it Devin!!  I appreciate your quick response and sorry for my delay.   With all the emergency prep going on at work this got pushed down in the que.  THANK you again.  I learn something new everyday!!  Be safe!

0 0
replied on March 17, 2020 Show version history

So how would you apply this to a table field?  The Name to populate after entering Wise ID and hitting enter key...

 

0 0
replied on March 17, 2020

It works similarly with tables, except the names are little different. The names are composed of "Field" plus the q number plus the row number.

So, if you preview your form as it stands, Date would be "Field22(1)", Wise ID would be "Field33(1)". If you add a new row, the second row of fields would be "Field22(2)" and "Field33(2)".

1 0
replied on March 19, 2020

Hey Devin,  That doesn't seem to be working.

0 0
replied on March 19, 2020

Give this a try, in the root of the javascript editor.

$(document).on("keydown", "input[id^='Field69']", function(e) {
  if(e.keyCode == 13){
    console.log("foo");
  }
});

The challenge with table and collection fields, is that they don't usually exist when $(document).ready fires. So, in this example, we're setting that event on the document root, but only if it matches a specific selector. That selector is a "begins with", so it should catch the input field in any row without needing to specify the row number.

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

Sign in to reply to this post.