Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

Column[
 {Grid[{{Style["code test", FontFamily -> "Arial", "Helvetica"]},
  {Grid[{{Style["input 2 #", FontFamily -> "Arial", "Helvetica"], 
    InputField[
     Dynamic[f1, If[# === Null, f1 = 0, f1 = Round[#, 00.001]] &],
      Number, FieldSize -> {4, 1}],
    Style["input 3 #", FontFamily -> "Arial", "Helvetica"], 
    InputField[
     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"], 
    InputField[
     Dynamic[f3, 
      If[# === Null, f3 = Round[#, 0.01], f3 = 00.001] &], Number,
      FieldSize -> {4, 1}],
    Style["input 4 #", FontFamily -> "Arial", "Helvetica"], 
    InputField[
     Dynamic[f4, 
      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!

share|improve this question
add comment

1 Answer

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.},

 Column[{

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

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

   Button[Style["Process"],
    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],
    ],
   Dynamic[message]

   }]

 ]

Alternatively the message could be a pop up etc.

share|improve this answer
    
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. –  R Hall Jun 10 '12 at 1:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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