Discussions

Expand all | Collapse all

Javascript refresh and position to a spot on the form

QuickBaseCoach Dev./Training03-21-2015 18:06

Xavier Fan03-21-2015 18:22

Esther Esther03-06-2018 15:49

Adam Keever03-01-2018 16:49

  • 1.  Javascript refresh and position to a spot on the form

    Posted 03-20-2015 21:55

    This works wonderfully. But is there an easy way to get it to also position to a spot on the form when it refreshes? Say to an anchor tag placed on the form like this?

    "<a name=DealerClaim></a>"



    var text NewStatus= If([Backorder Status]="Filled", "On Backorder", "Filled");

    var text URL = URLRoot() & "db/" & [_DBID_BACKORDER_LINES] & "?act=API_EditRecord"
    & "&rid=" & ToText([Record ID#])
    & "&_fid_6=" & $NewStatus;

    "javascript:" &
    "$.get('" &
    $URL &
    "',function(){" &
    "location.reload(true);" &
    "});"
    & "void(0);"





  • 2.  RE: Javascript refresh and position to a spot on the form

    Posted 03-21-2015 17:54
    Try this - see the bolded text to replace the line with "location.reload(true)"

    var text NewStatus= If([Backorder Status]="Filled", "On Backorder", "Filled");

    var text URL = URLRoot() & "db/" & [_DBID_BACKORDER_LINES] & "?act=API_EditRecord"
    & "&rid=" & ToText([Record ID#])
    & "&_fid_6=" & $NewStatus;

    "javascript:" &
    "$.get('" &
    $URL &
    "',function(){" &
    "location.href = location.href + '&d=' + Date.now() + '#DealerClaim';" &
    "});"
    & "void(0);"


    This constructs a new URL to go to. location.href is the current URL, and that's normally where the browser goes when you do location.reload(true).

    If you just put #DealerClaim at the end, the problem is that the browser doesn't refresh, and just jumps down to the anchor (which is normal browser behavior for anchors when you're on the same page already).

    So what we do is change the URL dynamically by putting in '&d=' + Date.now() - which puts a timestamp on the URL. e.g. &d=1426960116976

    Since the URL is now different every time you press the button, the browser reloads the page, and then jumps to the anchor position.


  • 3.  RE: Javascript refresh and position to a spot on the form

    Posted 03-21-2015 18:06
    Wonderful and thank you for the detailed explanation!


  • 4.  RE: Javascript refresh and position to a spot on the form

    Posted 03-21-2015 18:22
    You're welcome!


  • 5.  RE: Javascript refresh and position to a spot on the form

    Posted 03-01-2018 15:50
    Can this be applied to a section title or tab in a form?


  • 6.  RE: Javascript refresh and position to a spot on the form

    Posted 03-01-2018 16:29
    >Can this be applied to a section title or tab in a form?

    Adding a hash or fragment identifier (this is what the string after the # is called) to the end of the URL will result in the browser scrolling to that position. This is a general capability so you can form pinpoint references to a position on a page. Here is a pinpoint reference to your comment in the forum:
    https://community.quickbase.com/
    quickbase/
    topics/
    javascript-refresh-and-position-to-a-spot-on-the-form
    #reply_19360840
    You can locate the hash by inspecting the source - in Chrome right click, select inspect and look for name or id attribute nearby. That is the hash or fragment identifier to use. Here is a screenshot of me inspecting an arbitrary id in a random QuickBase form page that I had open revealing the hash is #tdf_0 for that particular position of the page:



  • 7.  RE: Javascript refresh and position to a spot on the form

    Posted 03-06-2018 15:49
    Thank you Dan


  • 8.  RE: Javascript refresh and position to a spot on the form

    Posted 06-05-2018 19:06
    This isnt working for tabs. It just drops me off at the end of the tabbed page


  • 9.  RE: Javascript refresh and position to a spot on the form

    Posted 03-01-2018 16:48
    Can it be applied generically so that if the button is used on a report it returns to the report but if used on a form in a tab it returns to that tab?  Side note: Why doesn't QuickBase just always return to the tab you were on in a form by default when you save or in reload?


  • 10.  RE: Javascript refresh and position to a spot on the form

    Posted 03-01-2018 16:50
    The code will refresh the page you are on, be it a report or a record.


  • 11.  RE: Javascript refresh and position to a spot on the form

    Posted 03-01-2018 17:03
    Yes, it reloads the page but when used in a form it reloads to the first tab even if the button was located on the third tab, for instance.


  • 12.  RE: Javascript refresh and position to a spot on the form

    Posted 03-01-2018 17:08
    I would have to do some testing to see if it is possible to position to a specific tab.  There are some tips on this thread that you can try and let me know.


  • 13.  RE: Javascript refresh and position to a spot on the form

    Posted 04-06-2018 01:12
    We've been stuck with this problem as well!! Been trying to find a way to direct the user to the next tab. The tabs make the form look a lot neater, but it also hides the content, which creates a very bad user experience......


  • 14.  RE: Javascript refresh and position to a spot on the form

    Posted 04-06-2018 15:34
    I did find that there is some code in the pages that does have a reference to the "activeTab". Now if I can only learn enough coding to make use of that fact. :) Here's the bit I found and put on a sticky note for future reference:

     $("#tabHolderSection.ui-tabs-uxv2").tabs({
            selected: QB.Storage.UserDB.get("activeTab", 0)


  • 15.  RE: Javascript refresh and position to a spot on the form

    Posted 04-06-2018 15:43
    I would not mess with that code. Off the top of my head I think QuickBase is using localstorage to persist the active tab on the form on a per user basis. If your goal is to load the page and automatically select a particular tab on the form you are better off using script to emulate a click on the specific tab. I am backed up at the moment but I will look at this over the weekend and clarify.


  • 16.  RE: Javascript refresh and position to a spot on the form

    Posted 04-06-2018 16:45
    Thanks for your insights. The point of all of this is that I want a way to return to the same place I already was after a button click, whether it is a report, tab on a form, whatever.

    The button script referenced in the first part of this post works wonderfully when placed wherever we want it. The only exception being that when the button is placed on a form tab, it never reloads that particular tab after being pressed, it returns to the first tab of that form.

    I know I can but I don't want to specify a specific tab being clicked because then I lose the ability to put this button wherever I want.


  • 17.  RE: Javascript refresh and position to a spot on the form

    Posted 03-01-2018 16:49
    Insightful. Thank you Dan.


  • 18.  RE: Javascript refresh and position to a spot on the form

    Posted 03-01-2018 17:02
    >Side note: Why doesn't QuickBase just always return to the tab you were on in a form by default when you save or in reload?

    For every user that wants one behavior there will be a dozen others that want some other behavior. The feature you want may be so microscopic that it never floats to the top of QuickBase's feature list.  This is especially true if the feature is cosmetic, has a workaround or more importantly isn't viewed  as a distinguishing product feature that will drive revenue.

    But your need is real and this is why QuickBase needs to give more attention to implement reasonable default behavior but provide a way to customize behavior for individual users. Today everyone is a snowflake and wants specific product features. Marketing has to realize that the  area at the head of the demand curve is almost equal the area in the tail of the demand curve. The rules have changed.