Forum Discussion

IvanWeiss's avatar
IvanWeiss
Qrew Captain
4 years ago

Rich Text Field Showing Javascript Code

Hi everyone,

I have a rich text field with a button that "completes" a task.  It shows up in multiple places (including my dashboard reports) so I used javascript to return it to the current page.  Below is the code I used.  The problem I have is that it is showing the javascript on the button (see screenshot).  Any ideas on how to hide that?

//Button Functionality:
//
//Check the current Task Stage
//
//If not Complete display button as gray
//Code should change the Task status to Complete

var text CLASS = If([Status]="Complete","btn btn-primary btn -sm","btn btn-default btn -sm");
var text FONTCOLOR = If([Status]="Complete", "#FFFFFF", "#A9A9A9");
var text LABEL = "Complete";

//Change the Task Status to Complete
var text URLONE = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" &
"&rid=" & [Record ID#] &
"&apptoken=HIDDEN" &
"&_fid_24=Complete" &
"&_fid_36=Changed Status to Complete" &
"&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=dr&rid="& [Record ID#]);

//Create edit functionality
var text URL = "href='" & $URLONE & "'";

var text LINK = "<a class='" & $CLASS & "' style='color: " & $FONTCOLOR & "; text-decoration: none'" & $URL & ">" & $LABEL & "</a>";

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

------------------------------
Ivan Weiss
------------------------------

19 Replies

  • DonLarson's avatar
    DonLarson
    Qrew Commander
    Ivan,

    Give them an icon to look at 

    var text IMG  =     "<img src=https://images.quickbase.com/si/48/016-email_0.png>"

     "<a href=\"javascript:" & "$.get('" & $URL  & "', function(){" & "location.reload();" & "});" & "void(0);\">"& $IMG &"</a>"


    ------------------------------
    Don Larson
    Paasporter
    Westlake OH
    ------------------------------
    • IvanWeiss's avatar
      IvanWeiss
      Qrew Captain
      Don, will that image show on the button?  The button is supposed to say "Complete" as it is to Complete a task....

      ------------------------------
      Ivan Weiss
      ------------------------------
      • DonLarson's avatar
        DonLarson
        Qrew Commander
        Ivan,

        You can substitute any image or text in that position of the href.    

        Technically you do not even have to change the name, you can still call it IMG but that is not good practice.   It is a declared variable of the type text.  

        Substitute

        var text Message= "Complete";

        and then stick $Message in the href.

        Since you are setting fields 24 and 36, you can add more logic to allow the User to only execute it once.
        If you add two more variables:

        var text TaskComplete = "Task is Complete";
        var text Executable =  "<a href=\"javascript:" & "$.get('" & $URL  & "', function(){" & "location.reload();" & "});" & "void(0);\">"& $IMG &"</a>";

        Your logic then becomes:

        If ( [FID24]<>"Complete", $Execute, $TaskComplete  )

        Substitute the real name of FID24 in the block.   If it has been marked then the Executable will not show and the User will see the message "Task is Complete" and not have a button to push.


        ------------------------------
        Don Larson
        Paasporter
        Westlake OH
        ------------------------------
  • Hi Ivan,

    Inserting Javscript into Quick Base formulas is an unsupported technique, and later this year we will begin blocking any new Javascript code from being added in this way. This is an important change to the platform as Quick Base was never designed for arbitrary code to be used in formulas, and it causes a lot of issues being able to support such apps and to pass them on to other admins in your company.

    We're looking into improving our formula language to allow for reloading the page, but in the meantime we recommend copying your formula for each report/dashboard it appears on.

    Thanks,
    Brian

    ------------------------------
    Brian Cafferelli
    Product Marketing Manager | Quick Base
    ------------------------------
    • AustinK's avatar
      AustinK
      Qrew Commander
      Should this be considered the announcement for Quick Base not supporting any type of JavaScript in formulas then? What happens to old formulas that are there already that have the same functionality? When will we expect to see this go live? Will there be a point where you do this to current formulas as well which will break them or will that not happen?

      Maybe I missed a previous announcement but this is the very first time I am seeing this being said.
      • BrianCafferelli's avatar
        BrianCafferelli
        Qrew Captain
        Hi Austin,

        While I didn't specifically intend to break news with my above post, yes this may be the first time this change has been mentioned on this forum.

        To clarify, inserting javascript code into formulas, branding, etc has never been supported but the change we're planning to make is to prevent javascript from being inserted in places where it was not already there, and to prevent changes to formulas that have previously had javascript added. javascript has always been intended to be used in code pages and that will continue.

        This change will not impact existing formulas that use javascript, in that they will be continue to work as-is after the change. We currently have no plans to stop supporting that. However, this seems like a good opportunity to remind folks that it is never a good idea to use javascript that way as those formulas could stop working at any time without warning. That continues to be the case, and those formulas will become more likely to break as we work to update the Quick Base UI over the next few years (for those who leverage DOM objects in their javascript-powered qb formulas).

        We'll have more details to share about these plans in the coming months.

        ------------------------------
        Brian Cafferelli
        Product Marketing Manager | Quick Base
        ------------------------------