This is a two part problem:

  1. I have a form that accepts both numeric and text inputs, then runs a function using a "process" Button. The issue I'm having is users that forget to fill out all of the fields and the function will not run. What I would like to do is to add some form of message dialog to the user that explains the problem, and preventing the function from running.

  2. Two of these InputFields feed a function that displays results in the notebook dynamically. Prior to having values in the InputFields for this dynamic function the code is visible in the section of the Grid the results will be displayed. How can I hide the code and just display the results after the InputFields have been populated?

Here is an example of the InputField code I'm working on:

 {Grid[{{Style["code test", FontFamily -> "Arial", "Helvetica"]},
  {Grid[{{Style["input 2 #", FontFamily -> "Arial", "Helvetica"], 
     Dynamic[f1, If[# === Null, f1 = 0, f1 = Round[#, 00.001]] &],
      Number, FieldSize -> {4, 1}],
    Style["input 3 #", FontFamily -> "Arial", "Helvetica"], 
     Dynamic[f2, If[# === Null, f2 = 0, f2 = Round[#, 00.001]] &],
      Number, FieldSize -> {4, 1}],
    Dynamic[data1 = Round[f2, .01] , CachedValue :> 0, 
     ContinuousAction -> False]}}, Frame -> None, ItemSize -> 10]},
{Grid[{{Style["input 4 #", FontFamily -> "Arial", "Helvetica"], 
      If[# === Null, f3 = Round[#, 0.01], f3 = 00.001] &], Number,
      FieldSize -> {4, 1}],
    Style["input 4 #", FontFamily -> "Arial", "Helvetica"], 
      If[# === Null, f4 = Round[#, 0.01], f4 = 00.001] &], Number,
      FieldSize -> {4, 1}], 
    Dynamic[data2 = Round[f4, .01] , CachedValue :> 0, 
     ContinuousAction -> False]}}, Frame -> None, 
  ItemSize -> 10]}}, Frame -> None], 
Button[Style["Process"], SelectionMove[yes =
 Mean[f2, f3], Method -> "Queued", All, ButtonCell]]}]
Print["yes", yes];

Code updated to provide a better example of the problem. Thanks for your help!


1 Answer 1


I can't give a complete testable answer because you haven't defined e.g. myInputs but it sounds like what you need is to test the field values and make sure that they meet certain criteria before processing. Therefore something along these lines should do the job (If you provide more complete information I can try for a better answer):

DynamicModule[{message = "", f1 = "", f2 = Null, etc. etc.},


   InputField[Dynamic[f1], String, FieldSize -> {15, {1, Infinity}}],

    Dynamic[f2, If[# === Null, f2 = Round[#, 0.01], f2 = 00.001] &], 
    Number, FieldSize -> {4, 1}],

    If[f1 =!= ""&&f2 =!= Null&& ...and so on ,
(* if criteria met then proceed *)
     SelectionMove[{y1, y2} = myInputs[{f1, f2, f3, f4, f5, f6}],
      Method -> "Queued", All, ButtonCell]],
(* else if criteria not met display a message to the user *)
     message = Style["please complete all fields", Red, Bold],



Alternatively the message could be a pop up etc.

  • $\begingroup$ Thanks for the tips Mike, I did not include the function nor the code for it because it's just too large to post here. The actual nb in question that feeds this function has 30 input fields in a complicated Grid to format everything nicely. That's why I couldn't post more code than I had. $\endgroup$ Jun 10, 2012 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.