Javascript refresh and position to a spot on the form

  • 1
  • 1
  • Question
  • Updated 1 year ago
  • Answered

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



Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,904 Points 50k badge 2x thumb

Posted 4 years ago

  • 1
  • 1
Photo of Xavier Fan

Xavier Fan, Champion

  • 590 Points 500 badge 2x thumb
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.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,904 Points 50k badge 2x thumb
Wonderful and thank you for the detailed explanation!
Photo of Xavier Fan

Xavier Fan, Champion

  • 590 Points 500 badge 2x thumb
You're welcome!
Photo of Adam Keever

Adam Keever

  • 1,520 Points 1k badge 2x thumb
Can this be applied to a section title or tab in a form?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
>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:

(Edited)
Photo of Esther

Esther

  • 702 Points 500 badge 2x thumb
Thank you Dan
Photo of G.Macri

G.Macri

  • 878 Points 500 badge 2x thumb
This isnt working for tabs. It just drops me off at the end of the tabbed page
Photo of Jill Engle

Jill Engle

  • 116 Points 100 badge 2x thumb
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?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,268 Points 50k badge 2x thumb
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.
Photo of Lorraine Chung

Lorraine Chung

  • 160 Points 100 badge 2x thumb
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......
Photo of Jill Engle

Jill Engle

  • 116 Points 100 badge 2x thumb
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)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
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.
Photo of Jill Engle

Jill Engle

  • 116 Points 100 badge 2x thumb
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.
Photo of Adam Keever

Adam Keever

  • 1,520 Points 1k badge 2x thumb
Insightful. Thank you Dan.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
>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.


(Edited)