7

I have an application using InputField to allow a user to dynamically update a data structure. In some cases the user will want to remove a string from one field and paste it into another. If this is done using cut and paste everything works okay, and the underlying data updates to reflect what is seen in the GUI. However, if the string is moved using drag and drop, the Dynamic in the source field does not appear to register the change of contents, although the destination field works as expected.

Here's an example:

test = {"string", ""};
Column[{
  InputField[Dynamic[test[[1]]], String],
  InputField[Dynamic[test[[2]]], String],
  Dynamic[test]
  }]

enter image description here

If I now drag and drop the string from the upper field into the lower field I get this:

enter image description here

The upper input field is now empty but test[[1]] still contains "string". This is a problem, because normally the Dynamic[test] line won't be there so the user relies on the input fields to correctly show the actual contents of test.

How can I fix this?

Simon Woods
  • 84,945
  • 8
  • 175
  • 324
  • 1
    what do you mean by drag and drop? Am I missing something? Also, I assume that ContinuousAction->True does not work too, does it"? – Kuba Sep 09 '13 at 11:52
  • What OS or mma version allows you to drag and drop these fields? – Mr.Wizard Sep 09 '13 at 12:00
  • @Kuba, thank you - ContinuousAction fixes it. Please consider posting that as an answer. – Simon Woods Sep 09 '13 at 12:05
  • 2
    @Mr.Wizard, version 9 on windows 7. Pretty sure it worked with version 7 on XP too. You do have to have drag and drop editing enabled in preferences. – Simon Woods Sep 09 '13 at 12:09
  • 1
    @SimonWoods oh, +1, I wasn't aware of the drag&drop built-in functionality :) each day something new :) – Kuba Sep 09 '13 at 12:14
  • I forgot about that option. I think years ago I tried it but I had too many accidental edits with it. – Mr.Wizard Sep 09 '13 at 12:18
  • 1
    @Mr.Wizard. I too tried it awhile back, but Mathematica's inept undo facility made it too risky. – m_goldberg Sep 09 '13 at 12:23
  • Unfortunately, my experiments with an EventHandler wrapper to handle "MouseDragged" failed to identify drag-and-drop events, so I would say this is another GUI functionality that cannot be handled correctly from within Mathematica, just like focusgain/loss, key release, etc. – István Zachar Sep 09 '13 at 13:15
  • @m_goldberg, I can't argue with the "risky" comment, you do have to be careful not to drop your selection in the wrong place or it will simply vanish. I did try turning it off for a while, but in the end decided that the convenience outweighed the risk. – Simon Woods Sep 09 '13 at 14:29

1 Answers1

5

The descriprion of the problem seemed to me similar to other issues I've faced in the past.

ContinuousAction->True

option for InputField helped me then and OP confirms that it helps in his case too.

So at the end, MWE introduced by Simon Woods should be expanded to:

Column[{
        InputField[Dynamic[test[[1]]], String, ContinuousAction -> True], 
        InputField[Dynamic[test[[2]]], String, ContinuousAction -> True], 
        Dynamic[test]
      }]
Kuba
  • 136,707
  • 13
  • 279
  • 740