Forum Discussion

QuickBaseCoachD's avatar
QuickBaseCoachD
Qrew Captain
10 years ago

Javascript refresh and position to a spot on the form

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);"



17 Replies

  • 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.
  • >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:

  • 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?
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      The code will refresh the page you are on, be it a report or a record.
    • JillEngle's avatar
      JillEngle
      Qrew Trainee
      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.
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      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.
  • >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.