Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Countdown timer in a list control

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Countdown timer in a list control

    I have a countdown timer in a list control that tells the user how much time they have left to complete a task. However, it's only showing up on the first record. I'm assuming there needs to be a loop to show through the rest of the list, but I can't figure that part out.

    Here's the javascript.

    Code:
    function countdown() {
    
    var currentDate = "tue Jan 09 2020 09:06 39";
    var currentTime = "19:14:14.9300000";
    // Set the date we're counting down to
    var countDownDate = new Date(currentDate).getTime() + 43200000;
    
    // Update the count down every 1 second
    var x = setInterval(function() {
    
      // Get today's date and time
      var now = new Date().getTime();
        
      // Find the distance between now and the count down date
      var distance = countDownDate - now;
        
      // Time calculations for days, hours, minutes and seconds
      var days = Math.floor(distance / (1000 * 60 * 60 * 24));
      var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
      var seconds = Math.floor((distance % (1000 * 60)) / 1000);
        
      // Output the result in an element with id="demo"
      document.getElementById("demo").innerHTML = hours + "h "
      + minutes + "m " + seconds + "s ";
      
      
        
      // If the count down is over, write some text 
      if (distance < 0) {
        clearInterval(x);
        document.getElementById("demo").innerHTML = "EXPIRED";
      }
    }, 1000);
    
    }

    I have the results showing in a Custom Control on the list with this.

    Code:
    function TimeLeft_render as c (ds as p, tmpl as p)
    'Specify the Xbasic that returns the HTML for this control. 
    'This function must return TimeLeft_render, which should
    'contain the HTML that will be displayed.
    'The 'ds' argument that is passed in contains the current 
    'values for each of the fields in the current List row. 
    'For example: ds.data("Firstname")
    
    '-------------------------------------------------------------------
    on error goto TimeLeft_xbasicError
    
    'Write Xbasic code here that returns the HTML to be displayed by this control
    	
    TimeLeft_render = <<%html%
    <p id="demo"></p>
    %html%
    
    
    end
    TimeLeft_xbasicError:
    TimeLeft_render = "Error in custom control xbasic: " + error_text_get() 
    end function
    Again, it just shows up on the first record. How would I loop to show them all? I will be making the 'currentdate' and 'enddate' a variable next. Once time has expired then the record won't show up anymore.

    Or is there a better way to do this.

    #2
    Re: Countdown timer in a list control

    No text.

    Comment


      #3
      Re: Countdown timer in a list control

      I've even tried putting all the code in a Virtual Javascript control, but couldn't get the return value right.

      Comment


        #4
        Re: Countdown timer in a list control

        Here's a more simple version of the code.

        I've inserted what I think is the loop, but it still only renders in the first record in the list.

        Code:
        function countdown() {
        
        
        		var lObj = {dialog.object}.getControl('CHECKOUTCART');
        		var data = {};
        	
        	for(i=0; i <lObj._data.length;i++) {
        		var currentDate = lObj._data[i].ItemDate;
        		var countDownDate = new Date(currentDate).getTime() + 43200000;
        		var x = setInterval(function() {
        
        
         			var now = new Date().getTime();
            
        			var distance = countDownDate - now;
            
          			var days = Math.floor(distance / (1000 * 60 * 60 * 24));
          			var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
          			var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
          			var seconds = Math.floor((distance % (1000 * 60)) / 1000);
          			var testing = "test"
          			
          		document.getElementById("demo").innerHTML = hours + "h "
          		+ minutes + "m " + seconds + "s ";
         
           		if (distance < 0) {
            		clearInterval(x);
            		document.getElementById("demo").innerHTML = "EXPIRED";
          		}
          
        	}, 1000);
        	
        
        	}
        }
        Now, if there's an easier way to get the value to the list, I'm open.

        Comment


          #5
          Re: Countdown timer in a list control

          Anyone have any idea on this?

          Comment


            #6
            Re: Countdown timer in a list control

            Hi David,

            Any chance you can create a sample ux with this list control and function with static data. Or a video showing us the properties of the List control and explain the expected output

            By looking at you code right way I would say this would only render the first row due to you only updating the id="demo", your Html would only contain one place where this would be true? Each item in the list even though you may of written id="demo" would of automatically appended a number like demo0 demo1 demo2 and so on...

            Outside of this technique you can you use javascript to compute the HTML within the List Layout simply use {@[scope].countDownTimer_resolve} within the location in the list controls layout and then select the javascript tab within the List Control (if you dont see this, tick the box in the bottom left hand corner) labelled Optional Tabs

            Create a function within here called countDownTimer_resolve with function args of data,context then proceed to write the code there - no need for a loop then or to know an id. As all the information you need is in data.
            just put a debugger in there and have a look.

            Code:
            debugger;
            return '<span>Time should show here</span>'
            Alex Collier

            "The spread of computers and the Internet will put jobs in two categories. People who tell computers what to do, and people who are told by computers what to do"

            AA Builds from 5221_5152 to Pre-releases >> Deploying to IIS in AWS

            Comment


              #7
              Re: Countdown timer in a list control

              Thank you, Alex. Sooo close. Yay!

              I simplified the code so we can get a sample result. I can add back in the rest later pulling the values from the list.

              This is what shows the timer on each record, but doesn't update every second. See the line right above the 'Remove' link in the attached image.
              Code:
              // Set the date we're counting down to
              var countDownDate = new Date("Jan 5, 2021 15:37:25").getTime();
              
              // Update the count down every 1 second
              //var x = setInterval(function() {
              
                // Get today's date and time
                var now = new Date().getTime();
              
                // Find the distance between now and the count down date
                var distance = countDownDate - now;
              
                // Time calculations for days, hours, minutes and seconds
                var days = Math.floor(distance / (1000 * 60 * 60 * 24));
                var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                var seconds = Math.floor((distance % (1000 * 60)) / 1000);
              
                // Display the result in the element with id="demo"
                return days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
              
                
              //}, 1000);
              GRAPHICS-0093.png


              This is what I want. The setInterval refreshes the timer every 1 second. It returns UNDEFINED as shown in the screen shot.

              Code:
              // Set the date we're counting down to
              var countDownDate = new Date("Jan 5, 2021 15:37:25").getTime();
              
              // Update the count down every 1 second
              var x = setInterval(function() {
              
                // Get today's date and time
                var now = new Date().getTime();
              
                // Find the distance between now and the count down date
                var distance = countDownDate - now;
              
                // Time calculations for days, hours, minutes and seconds
                var days = Math.floor(distance / (1000 * 60 * 60 * 24));
                var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                var seconds = Math.floor((distance % (1000 * 60)) / 1000);
              
                // Display the result in the element with id="demo"
                return days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
              
                
              }, 1000);
              GRAPHICS-0092.png

              Apparently, the code doesn't recognize the return value inside of the countdown loop. How do I get the return value from this?

              Comment


                #8
                Re: Countdown timer in a list control

                Hi David,

                Yes this is expected, as 1000 milliseconds later when interval starts and all subsequent intervals fire its not being called from the list layout render function to return data.
                You don't want to be creating a interval on every list item either.
                In your scenario you would only need one interval and use that to update all timers within the List as you had originally had.

                The return statement should create and store the required references for a setinterval function to compute the required timer (again bit in the dark on what you do and do not want) as there is so many ways to skin this cat.

                Essentially if all the timers are the same this would be the code

                Within the List Layout set the html that contains the timer elements for example

                HTML Code:
                  <div id="timer">
                    <div id="days" class="days"></div>
                    <div id="hours" class="hours"></div>
                    <div id="minutes" class="minutes"></div>
                    <div id="seconds" class="seconds"></div>
                  </div>
                In your javascript global function

                Code:
                // Set the date we're counting down to
                {dialog.object}.___countDownDate = new Date("Jan 5, 2021 15:37:25").getTime();
                
                function makeTimer() {
                  // Get today's date and time
                  var now = new Date().getTime();
                
                  // Find the distance between now and the count down date
                  var distance = {dialog.object}.___countDownDate - now;
                
                  // Time calculations for days, hours, minutes and seconds
                  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
                  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                  var seconds = Math.floor((distance % (1000 * 60)) / 1000);
                
                jQuery(".days").html(days + "<span>Days</span>");
                jQuery(".hours").html(hours + "<span>Hours</span>");
                jQuery(".minutes").html(minutes + "<span>Minutes</span>");
                jQuery(".seconds").html(seconds + "<span>Seconds</span>");	
                }
                
                setInterval(function() { makeTimer(); }, 1000);
                Maybe tee up a time and i will go through with you over skype or zoom. Free of Charge my email is [email protected] as long as you post the final solution back on the message board.
                Alex Collier

                "The spread of computers and the Internet will put jobs in two categories. People who tell computers what to do, and people who are told by computers what to do"

                AA Builds from 5221_5152 to Pre-releases >> Deploying to IIS in AWS

                Comment


                  #9
                  Re: Countdown timer in a list control

                  Thanks, Alex.

                  I guess context would help. I have an ecommerce application and when someone adds something to their cart, the field 'ItemDate' is filled with the current date and time and that item is reserved for that person for 12 hours. When they view the shopping cart, they are displayed with a timer on each item that counts down to 12 hours from the time they added the item to the cart. After 12 hours the item is then removed from their cart and someone else may purchase it.

                  So, each item counter would be different based on the time they added the item to the cart, counting down to 12 hours from that date/time.

                  The list control that shows the cart is CHECKOUTCART. Again, the field is ItemDate. And I have a Freeform List Layout.

                  So, THAT is my goal. Maybe that would make more sense?

                  Comment


                    #10
                    Re: Countdown timer in a list control

                    I guess it could be a calculated field then really, right?
                    NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                    Comment


                      #11
                      Re: Countdown timer in a list control

                      Yes I guess so, but I want it to count down as they look at it.

                      Comment


                        #12
                        Re: Countdown timer in a list control

                        I think Charles is pointing in the right direction.

                        You might begin by recording the time that the item was placed in the cart in the table.

                        UX components have timers. Maybe set it to 60 seconds, and use the onTimer event to update your display in the list items, display a warning that "You have One Hour left!" or to finally remove the item from the list (and refresh the list).
                        -Steve
                        sigpic

                        Comment


                          #13
                          Re: Countdown timer in a list control

                          I'm finding multiple ways to display the proper countdown on each record, but it's only counting down against the first record. All countdowns are the same, based on that first record. What might i be missing to pull each row's ItemDate?

                          Thanks, Steve. I will look at the timers. I like the idea of the "You have one hour left!".

                          Comment


                            #14
                            Re: Countdown timer in a list control

                            So my thought process is you have a timestamp (a DB field) for when it is placed in the cart to use as a start time, then a second field or text box in the list control that is used to hold the time left, and possibly another ( a text string) to display text based on the calculation. You can use javascript in the calculated field value to display a timer/countdown.
                            I am only thinking about the setup and not the actual code obviously but I think that's really what would give you what your looking for in the end.
                            NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                            Comment


                              #15
                              Re: Countdown timer in a list control

                              out of interest
                              // Display the result in the element with id="demo"
                              return days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
                              with 3 list items being displayed, what are the real id's you are using for each item?
                              Insanity: doing the same thing over and over again and expecting different results.
                              Albert Einstein, (attributed)
                              US (German-born) physicist (1879 - 1955)

                              Comment

                              Working...
                              X