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

Question

Question

How to Create a Spinner or Loader for Forms

asked on October 25, 2016

Hi all,

I was asked to post this. Hope it's useful to others as well.
 

1 0

Answer

SELECTED ANSWER
replied on October 25, 2016 Show version history

Feel free to add your own ideas below.

I highly recommend googling "css spinner" because there are many lovely spinner and loader animations available.

This is how I implemented the spinner:

---

Layout

1. Add a HTML element.

2. On the Basic tab, set the HTML to:

<div id="PDloader"></div>

3. On the Advanced tab, set the class to "PDloading"

CSS and Javascript

1. In CSS, add the following:

.PDloading {
  position: fixed;
  z-index: 999;
  overflow: show;
  margin: auto;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}

.PDloading:before {
  content: '';
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.3);
}

#PDloader {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 1;
  margin: -40px 0 0 -40px;
  border: 10px solid #f3f3f3;
  border-radius: 50%;
  border-top: 10px solid #3498db;
  border-bottom: 10px solid #3498db;
  width: 80px;
  height: 80px;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

2. At this point, there's enough completed to make to the spinner/loader visible. It will run stopped with a bit of JQuery (see below). Forms 10.1 Update 2 has a neat new function that allows us to stop the spinner once the page has loaded and run all of the lookups triggered by the Forms URL Parameters. See Point 3. for other options.

Code to turn off the spinner:

//once the form has loaded and initial lookups have run, this section will execute
$(document).on("onloadlookupfinished", function () {
  // the following line hides the spinner. 
  $('#PDloader, .PDloading').css('display' , 'none');
});

3. Perhaps you don't have 10.1 Update 2 OR you need to run the spinner when a lookup begins on the form. In my case, I have Lookup Rules which trigger Field Rules. Populating the data can take a while, so I use a spinner for that as well.

//this is the selector for my button
$('.autofill').on('click',function() {
  //turn the spinner on.
  $('#PDloader, .PDloading').css('display' , 'block');
  //this waits 5 seconds then disables the spinner.
  setTimeout(
    function() {
      $('#PDloader, .PDloading').css('display' , 'none');
    }, 5000
  );
});
14 0
replied on May 30, 2018 Show version history

Thanks Ben! This is really cool looking and useful!

I set it up to only show when certain fields are 'looking up'. Might help someone along the way:

//when the lookup runs on TravFormNum a spinner appears while the data loads
  $('#PDloader, .PDloading').css('display' , 'none');//initially not visible

  $(document).on("lookupstarted", function (event) {
  // the following line shows the spinner.
    	if (event.triggerId == "Field263") { //on travFormNum
    	$('#PDloader, .PDloading').show();
        }
	});
  
$(document).on("lookupcomplete", function (event) {
  // the following line hides the spinner.
  		if (event.triggerId == "Field263") { //on travFormNum
	  	 $('#PDloader, .PDloading').hide();
		}
	});
  

yes

3 0
replied on May 30, 2018 Show version history

Thanks, glad it's useful.

Yep 10.2 added the lookupstarted listener. Rather than updating the page, I linked (further down on this page) to https://answers.laserfiche.com/questions/108471/Can-we-get-a-lookups-complete-custom-event-listener-please#121241  but your update is well needed by now!

 

1 0
replied on September 30, 2018

I have 3 lookups that run off the same field. But the spinner hide's after the first lookup is complete, not after all lookups are complete. Am I missing something in my code?

$(document).on('lookupstarted', function(event) {
    $('#PDloader, .PDloading').show();
}); //end lookup started ----------------------------------------------

$(document).on('lookupcomplete',function(event){
  
    //Gets # of rows in Registered Devices and puts in hidden field
    $('#q57 input').val(Number($('.flagRemove .rpx').length));
  
    //If GUID is NOT blank - mark Registered Devices as Read Only
    if(event.triggerId === $('.trigUsrNm input').attr('id')){
            if ($('#q41 input').val() != '') {
                $('.flagRemove .rpx').each(function() {
                    $(this).find($('.flagRO input')).attr('backend-readonly', true).attr('readonly', true); 
                });
                $('.flagRemove .cf-collection-delete.selectable').css('display', 'none');
                $('.flagRemove .cf-collection-append').css('display', 'none');
            }  
      
      
      $('.macMask input').change(function(){
         $('.macMask input').mask('00:00:00:00:00:00', {'translation': {0: {pattern: /[0-9a-fA-F]/}}}); 
      });
      
      $('#PDloader, .PDloading').hide();

    }//end event triggerid  ------------------------------------
 
}); //end lookupcomplete  ------------------------------------------

 

0 0
replied on October 3, 2018

Hi Cassandra,

It looks like your testing for the first lookup to finish. You could set a flag for each lookup and test for each flag to be set as completed.

-Ben

 

1 0
replied on August 25, 2020

Hi Ben,

JS is not YET my strongest programming language. 

So I copied the code in your 1) 2) and 3) steps.  Works great, except the loader spins on the Thank You page (and never stops).

What am I missing?

 

Thanks for all you contribute to these pages.  I've plagiarized...  borrowed your code many times.   wink

1 0
replied on August 27, 2020

😁👍🏻

You're welcome!

The original code for the spinner wasn't mine either, I adapted/borrowed it, from a sample page of spinners somewhere else. 

I can't think what might be triggering it to start. Any chance you could paste your code for me to see? If you'd rather it wasn't public, would you be happy to send to my email address?

Regards 

Ben 

0 0
replied on August 28, 2020

I greatly appreciate your willingness to help... but I deleted the code.  It was causing the server to spike at 100% and stay super high after trying to get it to work on the 3rd time.  surprise  Opps.

Had to use task manager to End Task.   So I won't try that again during work time...  But I will attempt it again soon.

Thanks Again.

0 0
replied on August 30, 2020

When you're ready to try again, the problem can be resolved quickly by creating a second form, containing the same variables as the one with the spinner, but with no code. You would then set that form to be used as the Save form.

If the Save form is displayed to the user, then there will be extra work to update Save form every time the main form is updated. If it doesn't need to be displayed then there are other shortcuts that can be taken to reduce maintenance. 

Regards 

Ben 

0 0

Replies

replied on October 25, 2016

This is great!  Thank you very much!

0 0
replied on May 4, 2018 Show version history

This works great for form save/resume.

I'm also trying to use the spinner when the form is first accessed.  There is usually 5 seconds of white screen where we want to display the spinner.  What is the best way to start the spinner prior to the $(document.ready?  The spinner displays briefly just as it finishes the "ready" and prior to the finish of "lookup"  (#2 in how to stop the spinner).

0 0
replied on May 9, 2018

@████████this is awesome. Thanks. 

Do you know of a way to show the spinner when a lookup starts and hide it again when the lookup completes?

It works great onloadlookupfinished though. 

 

Jono

0 0
replied on May 9, 2018

I believe Forms 10.2 and above has a 'lookupstarted' event that you can use to show the spinner.

1 0
replied on May 9, 2018

Yep, Andy is correct.

I've included sample code at the bottom of this thread:

https://answers.laserfiche.com/questions/108471/Can-we-get-a-lookups-complete-custom-event-listener-please#121241

0 0
replied on October 23, 2018

So I am implementing your settings to include the spinner as described.  However, weirdly enough, the spinner is not completing on "lookupcomplete".  Makes me wonder if there is some lookup on the form that is not completing?

0 0
replied on October 23, 2018

Hi @████████,

We noticed that sometimes you have to use 'lookupstarted' as the complete trigger and the 'lookupcomplete' as the start trigger. Totally backwards.

 

 

0 0
replied on May 1, 2019 Show version history

Hey there,

My coding skills are barely good enough that I can copy what others have done and make it work on my form so I'm sorry if this question is dumb. I have a custom html field on my form containing a load message that I want to appear when a lookup is being executed and to disappear when the lookup is finished. I don't need the fancy spinner... just the simple field is sufficient. My form is not utilizing a lookup based on URL parameters, just input on a particular field. I can't get it to work and I'm not sure where I'm going wrong so I was wondering if someone could take a look? Maybe I am not using the right number of equal signs or maybe missing curly bracket?

Here is my html field:

<div id="PDloader"><p style="text-align: center;"><b>Loading... Please wait.</b></p></div>

 

 

And here is my JS:

$(document).ready(function () {
  
     $('#PDloader, .loadingParcel').css('display' , 'none');
     
       $(document).on("lookupstarted", function(event) {
       if (event.triggerID == "Field177"){
         $('#PDloader, .loadingParcel').show();
       }
     });
     
     $(document).on("lookupcomplete", function(event) {
       if (event.triggerID == "Field177"){
         $('#PDloader, .loadingParcel').hide();
       }
     });
});

Any help would be appreciated!!!

0 0
replied on May 1, 2019

Hi Chelsey,

Would it be sufficient to use a Field Rule to show your Custom HTML message when the required field is blank still? It would hide the Custom HTML once the lookup is complete and populated the field.

0 0
replied on May 2, 2019

I did initially attempt it this way. The issue was that the message would show as soon as a character was typed into the lookup trigger box instead of waiting for the user to tab or click out - which is what is actually initiating the lookup. I thought it would be confusing for users to see the loading message while they were typing. They might think that the lookup is already working without tabbing or clicking out and so I was worried that they would not leave the input box which could lead to them thinking the form was broken.

0 0
replied on September 10, 2020

Hi everyone,

The new LF Forms 10.4.5 includes a spinner!

Added a loading spinner to indicate that the page is working when accessing lookup values.

  • Note: If any form already uses customised JavaScript to indicate lookup execution, please check and update if necessary.
0 0
replied on September 10, 2020

The spinner appears next to the initiating field as far as I can see. Not a big one that is super obvious for those sight challenged clients lol

Jono

0 0
replied on September 11, 2020 Show version history

If that's true, then I guess it won't be helpful if the lookup field is hidden or on another page. Hmm... I'll have a look into that this week.

p.s. yes, we're all getting old 😅😎

1 0
replied on August 4, 2021 Show version history

Hi @Jonathan Roberts yes, I see what you mean. It doesn't always show either. Or at least, there are some moments when I don't see the spinner but the fields are still blank.

-Ben

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

Sign in to reply to this post.