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

Question

Question

Run Javascript after a form is fully loaded

asked on October 23, 2023

I have a Laserfiche form with lookup rules. One of the lookup rules populates a table on the form. I would like to run javascript when the form is fully loaded, including the table being fully populated.

I have tried

$(document).ready()

and 

$(document).on("ajaxStop", funct)

but both of these events occur before the form is finished loading.

Is there a simple, reliable method I have missed or do I just have to guess based on elapsed time?

0 0

Answer

SELECTED ANSWER
replied on October 23, 2023

In the Classic Designer, you can use the following to trigger after lookups are complete. 

$(document).on("lookupcomplete", function (event) {
  alert('lookup complete');
});

 

This one will run after completion of lookups that happened immediately upon form load (so this is likely the one you want for your use case): 

$(document).on("onloadlookupfinished", function (event) {
  alert('lookup complete');
});

 

For additional information, I've referred many times to this post and its comments that happened early in version 10 of Forms, when these events were added.

2 0
replied on October 23, 2023

Wow! That's exactly what I was wishing for. I should have asked that question months ago! 

Thanks you!

1 0

Replies

replied on February 13, 2024

What if you don't have any Lookup Rules?

0 0
replied on February 13, 2024

I just ran a quick test on a trivial form without any lookup rules. The "lookupcomplete" event described by Matthew didn't fire, but "onloadlookupfinished" still fires on a form without any lookups, so I suggest you use that. I haven't tried it in production but I can't think of any reason it wouldn't work.

0 0
replied on February 13, 2024

If you are just wanting code that runs when the form is loaded, the standard is the document ready function:

$(document).ready(function () {
  alert('Hello World!');
});

 

It's a pretty commonly used thing, you'll see it on the majority of code examples throughout LFAnswers.

Note that this is just the Classic Designer, the New Designer Javascript is very different.

1 0
replied on February 13, 2024

Thanks for the replies, very helpful!

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

Sign in to reply to this post.