# How to write 1.0 in InputFields with ContinuousAction and Number constraint

With the concept of user responsiveness in mind, I’ve tinkered a couple of small apps that are supposed to be eh… responsive, i.e. calculating without having to press enter.
They all rely on InputField with ContinuousAction and shall only accept numbers and decimal points.

Code snippet as an example:

field1 = 1;
Grid[{{"Input a number"}, {InputField[Dynamic[field1, (field1 = #) &],
Number, ContinuousAction -> True]}}]


Everything works except when trying to write 1.01 since it halts at the lonely zero which isn’t considered a Number. Question:
So my question is, how to make InputField accept a lonely zero after the decimal point as a number while continually evaluating the users every keystroke.

Edit: The final goal is to get a quick and responsive CDF. I believe true ContinuousAction will open up for a lot of small useful applications.

• There is somewhere closely related question. Current behaviour is quite poor. Specially in .CDF context when only Number fields are allowed. If you are not going to put it in CDF I'd work with strings
– Kuba
Feb 1 '15 at 13:57
• @Kuba Yes I asked a compound question where this problem was mentioned. But since I haven't solved it yet, I tried to chisel out a new and hopefully clearer question :) Feb 1 '15 at 13:59
• @Kuba Any trick up your sleeve as to achieve the same effect? I have these old programs I wrote in Flash ActionScript that are extremely responsive. I would very much like to rewrite them in Mathematica. Feb 1 '15 at 15:08
• Why not use Expression instead of Number. While you could use String you will need to convert to be able to use the string number. Feb 1 '15 at 22:04
• The problem is that with ContinuousAction -> True is that the input 1.0 is immediately converted to a number and displayed, the number being the real number one. The number one is displayed automatically as 1., which removes the 0 from the InputField. I seriously doubt there is a way to hack InputField in a way that it will work in CDF (or that there is any way at all). - [Should this be an answer?] May 4 '15 at 10:41

From my comment:

The problem is that with ContinuousAction -> True is that the input 1.0 is immediately converted to a number and displayed, the number being the real number one. The number one is displayed automatically as 1., which removes the 0 from the InputField. I seriously doubt there is a way to hack InputField in a way that it will work in CDF. One needs access to the input string (or an equivalent), but only numbers are disallowed; see https://www.wolfram.com/cdf/faq/details-for-mathematica-programmers.html.

• And in FreePlayer only Numeric number field is available. :)
– Kuba
Oct 31 '15 at 14:56
• @Kuba Thanks. I added a link to a (current) reference for the limitation. Oct 31 '15 at 15:22

Does this do what you need?

Grid[{{"Input a number"}, {InputField[
Dynamic[field1, If[NumberQ[#], field1 = #, field1 = Null] &],
Expression, ContinuousAction -> True]}}]

• @Kuba Why? .... Feb 1 '15 at 22:12
• @Kuba the OP makes no mention of CDF Feb 1 '15 at 22:15
• Ahh, there was a comment from OP that the final goal is CDF, I don't know why he deleted it.
– Kuba
Feb 1 '15 at 22:15
• @Kuba ok, well I'll leave the question for now and delete it if he confirms he wants to deploy in CDF Feb 1 '15 at 22:16
• @Kuba actually I'll be away the rest of the week so will make it a community wiki then anyone can delete ...right? Feb 1 '15 at 22:17