# problem with copying Dynamic result

After running below code

   DynamicModule[{temp},
data = Range[10];
temp = {};
Column[{
Button["reset", temp = {}],
TogglerBar[Dynamic[temp], data, Appearance -> "Horizontal" -> {Automatic, 5}],
Dynamic[temp]
}]
]


I got

Now I want to copy the dynamically generated list and paste it elsewhere. But I found sometimes it works, sometimes it is not. You can see below gif

What is wrong with my code? Why sometimes it gives temp$$, sometimes not? How to make dynamic results easy to copy? Update With Kuba's method to view "SelectionData", it is clear what is going on, see below gif. So proper selection will give expected result instead of temp$$

• It is probably a subtle problem with what you really select, if whole DynamicBox or not. To achieve a stable behavior you can use InputField@Dynamic[temp] for example. – Kuba Sep 14 '16 at 11:34
• Yes, I think, @Kuba is right about whether you select the whole DynamicBox or its contents. -- The menu command Cell > Show Expression will reveal what you actually pasted. – Michael E2 Sep 14 '16 at 11:36
• Hi, @MichaelE2. But I can not see any difference between two cases by looking at " Show Expression". where is the difference? – matheorem Sep 14 '16 at 11:54
• @matheorem with ShowExpression you only see what is written in a notebook file. There is another layer, on that FE really displays, so DynamicBox is there but FE keeps track what it really represents. In this case a box representation of temp. More or less ;) – Kuba Sep 14 '16 at 13:29
• Syntax highlighting can assist your selection process. If the cursor is placed directly after the }, then { } will be highlighted and you'll be selecting the right thing. If the cursor is placed too far after }, then there is no syntax highlighting and you'll be selecting the DynamicBox. One can use the arrow key to move to the correct position. Double-clicking on { or } also results in a correct selection. – Karsten 7. Sep 15 '16 at 7:59

### Quick fix:

To achieve a stable behavior you can use e.g. InputField @ Dynamic[temp].

It is probably a subtle problem with what you really select, if whole DynamicBox or not.

To see what is going on you can use

Dynamic @ InputForm @ CurrentValue @ "SelectionData"


and check what is selected in certain steps, sometimes it is

DynamicBox[ToBoxes[temp$$, StandardForm], ....] (*displayed as temp$$*)


and sometimes a RowBox with numbers. In the latter case you got what you were expecting.

• InputField is great! upvoted! Thank you so much! I need more time to understand the remaining part : ) – matheorem Sep 14 '16 at 11:50
• "SelectionData" works like magic, very interesting : ) – matheorem Sep 15 '16 at 7:38
• @matheorem I'm glad it fits yor needs :) Thanks for the accept. – Kuba Sep 15 '16 at 7:38