1 Reply Latest reply on Jan 9, 2015 8:37 AM by Jon Tara

    SB1 pager controls fire twice

    David Carson

      I'm developing a simple application for the SB1 Smart badge. The app displays 4 items in a list with a pager but when I click on the PageUp or PageDown buttons the event fires twice - resulting in only the 'odd' numbers pages being accessible.

       

      I have checked my code and the event is only attached once

       

                      $('#pageDown').unbind('click').click(function (e) {

                          console.info("Page Down");

                          displayItems(currentPage + 1);

                      });

       

      Running locally on Chrome, if I open the Dev Tools and put a breakpoint on the 'console' line, then click the page down button the code execution stops as expected but then I continue execution of the code it runs fine, i.e. the event is NOT fired again. Basically trying to observe the behaviour, changes the behaviour (not helpful).

       

      Following advice from another post I've wrapped the code in an 'events.subscribe' block like so:

       

             asl.events.subscribe(asl.events.types.loaded, function (r, s) {

                      // console.log(asl.prv.locale);

                      $('#pageDown').unbind('click').click(function (e) {

                          console.info("Page Down");

                          displayItems(currentPage + 1);

                      });

                  });

       

      But now nothing happens when I click the button - I'm assuming that this is because I'm not actually running on the device but locally in Chrome, but I'm not sure.

       

      Can anyone shed any light on the above?

       

      Thanks in advance

        • Re: SB1 pager controls fire twice
          Jon Tara

          You haven't shown any HTML. Is there an href on the button?

           

          You need to call e.preventDefault() or else return false from your click function to prevent the default action on the button. (preventDefault() is preferred).

           

          Are you using jQuery Mobile? (It is included by default in Rhodes projects. If you aren't using it, you would have removed it yourself.)

           

          Be careful about using IDs with jQuery Mobile. They must be unique across all of your pages. (Not just within a current page.) I avoid using IDs completely. Did you use the ID pageDown in two different pages? It sounds like you may have.

           

          Why are you using unbind()? That raises a smell. When I see unbind(), I almost always find that it is a workaround for some "mysterious" problem. Did you have a mysterious problem that unbind() fixed?