Copy to clipboard: Multi-line referenced table
Hi Folks,
Here's a doozy (well, hopefully not). I'd like to add a 'Copy' button below a referenced table "Project Details". Within that table, I'd like to copy a couple of fields: "Item Detail" and "Item Total".
I'd like for them to paste like this:
Item Detail #1 ..........$Item Total #1
Item Detail #2 ..........$Item Total #2
Item Detail #3 ..........$Item Total #3
and so on...
I've come to figure out that there's not a way to do that with an actual button, so by combing through other Ninox threads and questions I've figured out how to style a button using a formula field.
Additionally, I've been working with AI to try and put some code together to get the formatting I've outlined above.
I'm getting there, but pretty hung up on adding the paragraph returns (line breaks) after each line.
As it stands the current code (copied below) returns something like this:
Item Detail #1Item Detail #2Item Detail #3..........$
Item Total #1Item Total #2Item Total #3
So, the <br> is working, but not doing it for every line, nor is it in the correct order. Here's the code I have currently:
let outputList := "";
let details := 'Project Details';
for r in details do
outputList := outputList + r.'Item Details' + " ...............$ " + r.'Item Total' + "<br>"
end;
html("
<style>
.customButton {
height: 25px;
width: 105px;
background-color: #5e6e9c;
border: none;
color: #fff;
font-weight: bold;
padding: 5px;
}
</style>
<button class='customButton' onclick='CopyEstimate(getDetails())'>Copy Estimate</button>
<script>
function getDetails() {
return '" +
if 'Project Details' then
'Project Details'.'Item Details' + " ...............$ " +
'Project Details'.'Item Total'
else
"No Project Details Found"
end +
"';
}
function CopyEstimate(str) {
var el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
</script>")
Any ideas? Thank you in advance!
10 replies
-
There are two ways to do a paragraph return/line break/carriage return.
1) just add a paragraph return:
let outputList := ""; let details := 'Project Details'; for r in details do outputList := outputList + r.'Item Details' + " ...............$ " + r.'Item Total' + " " end;
Notice at the end of line 4, I just hit the enter key.
The big problem I have with this method is that is messes up the display of the code for my eyes.
I like using a variable:
let pmark := urlDecode("%0A"); let outputList := ""; let details := 'Project Details'; for r in details do outputList := outputList + r.'Item Details' + " ...............$ " + r.'Item Total' + pmark end;
Here we use the urlDecode() function to convert ASCII code for a line feed into a paragraph mark.
-
said:
thank you! Any ideas about how to get things to order like this (with the paragraph returns)?
Item Detail #1 ..........$Item Total #1 Item Detail #2 ..........$Item Total #2 Item Detail #3 ..........$Item Total #3You can try:
let pmark := urlDecode("%0A"); let details := 'Project Details'; let outputList := for r in details do r.'Item Details' + " ...............$ " + r.'Item Total' end; join(outputList, pmark)
Here we use the join() command to take the array created in line 3 and add a paragraph mark in between array items. This way does not add a paragraph mark after the last array item, like it would if you hard coded the paragraph mark into the text line.
-
said:
I'm not sure what I'm getting wrong... below is all of my current code. When I 'click the button' (formula) and paste it, this is what I'm getting:I think it has something to do with this part of your code:
<button class='customButton' onclick='CopyEstimate(getDetails())'>Copy Estimate</button> <script> function getDetails() { return '" + if 'Project Details' then 'Project Details'.Id + 'Project Details'.'Item Details' + "..............." + 'Project Details'.'Item Total' + " " else "No Project Details Found" end + "'; }
Why do you have the first part of your code when it looks like this part of the code does all of the heavy lifting. Lines 5 - 9, is the code that creates the text for the clipboard
I'm guessing you can move the first part of the code into the if statement:
<button class='customButton' onclick='CopyEstimate(getDetails())'>Copy Estimate</button> <script> function getDetails() { return '" + if 'Project Details' then let pmark := urlDecode("%0A"); let details := 'Project Details'; let outputList := for r in details do r.'Item Details' + " ...............$ " + r.'Item Total' end; join(outputList, pmark) else "No Project Details Found" end + "'; }
But I don't work with function() at all so I can't be sure if it will work.
-
said:
Below is what I've placed in, but now, it doest seem like anything is working...You are still putting in all the code.
Let us make this a bit simpler.
Create a new formula field and put this code in it:
let pmark := urlDecode("%0A"); let details := 'Project Details'; let outputList := for r in details do r.'Item Details' + " ...............$ " + r.'Item Total' end; join(outputList, pmark);
Just the code above. Nothing below or above it.
Content aside
- 1 yr agoLast active
- 10Replies
- 318Views
-
2
Following