# Module Inside ToBoxes or MakeBoxes

Does someone mind explaining why Module doesn't seem to work while inside ToBoxes or MakeBoxes.

SetAttributes[AutoInputField, HoldAllComplete];
AutoInputField /: MakeBoxes[AutoInputField[
list_: {}, displayNum_: 3, imageSize_: 100], form_] :=
ToBoxes@Module[{x = "default"},
x = "default";
Column[{
InputField[Dynamic@x, String, ContinuousAction -> True,
ImageSize -> imageSize],
Dynamic@x
}
]
];
AutoInputField[]
AutoInputField[]


Ideally x should be set to "default", but as of right now x isn't taking on any value. Surprisingly Module is successful at scoping the different value because the two InputFields values don't change interactively.

I am looking for a way to modify/set the value of x inside the Module.

-
Someone has point this out to you in one of the previous question but let me quote John Fultz: "Module variables should never appear inside Dynamics or Manipulates internal to that Module.". That's ofcourse a side note. – Kuba Sep 13 '13 at 6:38
@Kuba DynamicModule works. Although it works, I am just assuming that is the technique that is best advised. – William Sep 13 '13 at 13:50
I have found the link that you are referring to here Quit useful. What do you think would be most appropriate: you posting a response, me posting a response, or closing/deleting the question? – William Sep 13 '13 at 17:43
Remark about DynamicModule was only a side not. I must admit my I have not focus well on your question so I'm not going to answer :) If you've solved your issue it is encouraged to self-answer. – Kuba Sep 13 '13 at 19:05

It appears using DynamicModule solves the issue quite well.

SetAttributes[AutoInputField, HoldAllComplete];
AutoInputField /: MakeBoxes[AutoInputField[
list_: {}, displayNum_: 3, imageSize_: 100], form_] :=
ToBoxes@DynamicModule[{x = "default"},
x = "default";
Column[{
InputField[Dynamic@x, String, ContinuousAction -> True,
ImageSize -> imageSize],
Dynamic@x
}
]
];
AutoInputField[]
AutoInputField[]


Although John Fultz's answer here was not about Module values it appears his rules there hold true for this question also.

-
This is exactly what DynamicModule was designed to do, and it is exactly what I've warned against where Module is concerned. In 9.0.1, the code in your question would have colored red to warn you, except for a bug that causes it to not color for Dynamic@x (as opposed to Dynamic[x]). – John Fultz Sep 14 '13 at 23:09
Incidentally, I've fixed the lack of proper syntax highlighting on Dynamic@x. In my development version, the non-DynamicModule version now highlights the x red in all appropriate places. – John Fultz Sep 15 '13 at 21:54