Does the browser component 'copy' work? If so, how to apply data to be copied

Hey all,

Tried using the browser copy component/function - when using it - there is no option to select data for it to copy, but it does present a () so I inserted the data from that row, but no action took place.

Keen to know if anyone has used this, and if it works, how best to use it?

It does work, but you first have to use the selectAll() and then the copy() or there will be nothing selected to copy, alternatively you can manually select / highlight an area.

If you still need guidance on it, I can look through my old code to find it, but a tip I can give for now is that the browser1.selectAll() takes no parameters and selects everything on the entire webpage, so to make the select all work as you more than likely need, add it to a <textarea> form element so the select all only selects all from inside the <textarea>.
The browser1.copy() only copies what is selected at the time.

Therefore if you have

<textarea id="my_textarea" class="form-control" dmx-on:click="browser1.selectAll();browser1.copy()"></textarea>

Then it will copy everything from the text area when the user clicks on it.

The hard part is getting all the text you want to populate inside the textarea, especially if its from a server action with a database multi query as then you have to try get through all the arrays inside it.
Something like

<textarea id="my_textarea" class="form-control" dmx-on:click="browser1.selectAll();browser1.copy()" dmx-bind:value="serverconnect1.data.query1.values(`db_col1`+'\t'+`db_col2`).join(',').replace(',', '\n')"></textarea>

Please take care of backticks vs single quotes vs double quotes used in the .values().
This will produce the entire result of the database query with each column separated by a tab and each row on a new line, which then works perfectly to paste inside a spreadsheet application and retain the column / row relationships.

2 Likes

Wow, thank you for all that @psweb - fortunately I only want to copy single items that appear in a repeat, so iā€™m confident reading through this that I can get it working. First task for tomorrow :slight_smile:

Thank you again!

did you get this working. I have the same need at the moment.

I would suggest having it with a selector to tell it to copy the value of a field or copy text directly from the database, I also tried the Write text to clipboard so far for me it can copy static text I add there but if I select a field form he database it just gives a js error