# Palette with editable InputField

I need a Palette with editable InputField.

When I try the code CreatePalette[Pane[InputField["Enter a string"]]] it makes the pallete but all input goes into an open notebook, not into the InputField.

I just need a Palette with editable InputField. How it can be done?

• Palettes seem to be made for buttons, I'm pretty sure you need CreateDialog. – Kurt Mar 30 '15 at 17:34
• Care to provide some code to show how CreateDialog can be used to address the OP's issue? It would make your answer more helpful and probably solicit some rep. – bobthechemist Mar 30 '15 at 17:54

The following code should fix the problem:

CreatePalette[Pane[InputField["Enter a string"]], WindowFloating -> False,
WindowClickSelect -> True];


But as we figured out it is not!

I read all available information about WindowClickSelect and WindowFloating options in Mathematica documentation.

I didn't find any notices that we can't use the options simultaneously. I also didn't find any cautions that we can't use the options with Mathematica palettes.

Thus, such unexpected behavior is probably a bug in Mathematica. I advice to contact Wolfram support team regarding this bug.

• It works! :) Thank you Helen! – Norb Mar 15 '12 at 7:41
• I found strange behavior. When use this option I can't execute a cell anymore (Mathematica beeps). F1 to open help system and Ctrl+S to save the nb doesn't work correctly. – Norb Mar 15 '12 at 7:49
• Try to set the option WindowFloating to False. – helen Mar 15 '12 at 8:02
• WindowFloating really helps. But when I use these options, another problems have arisen. As far as I understand, now the focus of the palette on the InputFiles. So, when I try to use another Mathematica palette to paste something to the notebook, it is pasted into the InputFiled of the my palette. Moreover, I can't use PasteButton in my palette (Mathematica beeps again). So, even with these options I can't create the pallete that works correctly. – Norb Mar 15 '12 at 8:26
• On Mathematica v11.0, this code runs from a notebook (and works), but doesn't seem to allow the palette to actually be installed. The Install Palette drop down menu doesn't recognize the new palette (assuming a WindowTitle is inserted into your code) to install it. – Todd Allen Jan 6 '17 at 1:09

It seems you can't have everything in one, but maybe everything in 1.5 will be ok:

CreatePalette[
DynamicModule[{string = ""},
Pane[
Button[
InputField[Dynamic@string, String],
string = InputString["", string],
Appearance -> None, Method -> "Queued"
]]]

];


As of 11. something this is nice and easy, if you're on Mac. It seems this does not work for Windows.

We'll leverage FrontEndMoveCursorToInputField and SetSelectedNotebook to temporarily overcome the WindowClickSelect issue.

paletteInputField[specs__] :=

With[{uuid = CreateUUID["input-field-"]},
EventHandler[
InputField[specs, BoxID -> uuid],
{
"MouseClicked" :>
If[EvaluationNotebook[] =!= SelectedNotebook[],
CurrentValue[
EvaluationNotebook[],
{TaggingRules, "OldSelection"}
] = SelectedNotebook[];
SetSelectedNotebook[EvaluationNotebook[]];
FrontEndMoveCursorToInputField[EvaluationNotebook[], uuid]],
"MouseExited" :>
(
SelectionMove[EvaluationCell[], All, Cell];
SetSelectedNotebook[
CurrentValue[
EvaluationNotebook[],
{TaggingRules, "OldSelection"}
]
]
),
PassEventsDown -> True
}
]
]


This then works (almost) exactly as expected:

CreatePalette[
paletteInputField["asdasd", String],
WindowMargins -> Automatic,
SystemClosingSaveDialog -> False,
WindowSize -> 300
]


Note the "MouseExited" call there. This just passes focus back to the previously selected notebook so nothing wonky happens and moves the selection point for aesthetic reasons.

And we don't lose WindowFloating either.

• On Win10 the content of IF is selected but when I start typing it writes to previously used notebook. – Kuba Nov 24 '17 at 8:43
• @Kuba ah the joys of the FE. I guess this is maybe a Mac-only solution then. What happens if you stick a SetOptions[EvaluationNotebook[], Selectable->True] in the "MouseClicked" call? – b3m2a1 Nov 24 '17 at 8:45
• Nope, same story, guess OS dependent. But I wonder how much use if of that if it will break/interfere with typical palette's buttons which assume InputNotebook is not the ParentNotebook. Hmm, maybe this boils down to 'how to create floating dialog' rather than 'editable palette'. – Kuba Nov 24 '17 at 8:49
• @Kuba I can get around that one using "MouseExited". The not properly getting focus issue is more concerning to me. – b3m2a1 Nov 24 '17 at 8:55
• Another comment, don't feel targeted, I just want to point issues people will likely face because I deal with people who try to break my code on daily basis :) So, first of all "MouseExited"` is commonly used but still undocumented :(, second, when you move cursor during typing it will switch selection, it is clearly unlike any input field/ text area experience so people will complain / find it cumbersome. Again, not your fault, I know the pain. – Kuba Nov 24 '17 at 9:05