1

I was wondering if it is possible to add a title to

InputField

As far as I know, you can only add a FieldHint, this one will disappear however as soon as the user has entered input. But I still want the user to know what his input corresponds to. So I was wondering if there is some sort of a workaround for that.

Edit: Tried to implement it but it shows up with {}, which is not what I want, could it be that the problem is that I use Column, instead of Grid? Documentation would suggest otherwise...

Panel[Column[{{"Purchase Price", 
InputField[Dynamic[purchaseprice], Number, 
 FieldHint -> "Purchase Price", 
 ImageMargins -> 10]}, {"Equity Capital", 
InputField[Dynamic[EK], Number, FieldHint -> "Equity capital", 
 ImageMargins -> 10]}, {"Mortgage rate in %", 
InputField[Dynamic[mortgagerate], Number, 
 FieldHint -> "Mortgage Rate in %", 
 ImageMargins -> 10]}, {"Supplementary Costs per annum", 
InputField[Dynamic[supplymentary], Number, 
 FieldHint -> "Supplementary costs per annum", 
 ImageMargins -> 10]}, {"Payback Period", 
InputField[Dynamic[paybackperiod], Number, 
 FieldHint -> "Payback Period", 
 ImageMargins -> 10]}, {"Gross Income per annum", 
InputField[Dynamic[grossincome], Number, 
 FieldHint -> "Gross Income per annum", 
 ImageMargins -> 10]}, {"Calculatory mortgage rate", 
InputField[Dynamic[calcrate], Number, 
 FieldHint -> "Calculatory mortgage rate", ImageMargins -> 10]}, 
Dynamic@If[
 grossincome*0.33 > (purchaseprice - EK)*mortgagerate/100 + 
   supplymentary + 
   Max[{((purchaseprice - EK) - 0.66*purchaseprice)/paybackperiod,
      0}], TextCell[
  "Congratulation you are qualified for a mortgage", "Subtitle"], 
 Dynamic[Text["You only have "] Text[
    Round[((purchaseprice - EK)*mortgagerate/100 + supplymentary +
           Max[{((purchaseprice - EK) - 0.66*purchaseprice)/
             paybackperiod, 0}])/purchaseprice*100] Text[
      "% instead of 33%"]]]]}, 
Background -> 
Dynamic@If[
 grossincome*0.33 > (purchaseprice - EK)*mortgagerate/100 + 
   supplymentary + 
   Max[{((purchaseprice - EK) - 0.66*purchaseprice)/paybackperiod,
      0}], Green, Red]]]
julsto
  • 143
  • 6
  • Can you provide a bit more context about how you are using InputField? – kickert Jun 26 '18 at 14:57
  • Hope this helps – julsto Jun 26 '18 at 15:17
  • You have two options: (1) use Column like you did now, then each {"label", inputfield} needs to be wrapped in a Row. (2) You use Column like you did, but you use a Grid for your inputs like Grid[{{"label 1", input1}, {"label 2", input2},..}]. – halirutan Jun 26 '18 at 15:21
  • Looks like you have an extra set of {} in your code. Try removing the curly brackets around each row. You might want to then adjust the text and alignment, but that works on my end. – kickert Jun 26 '18 at 15:22

1 Answers1

2

The solution is to learn to help yourself. You know that Manipulate provides an easy way to have labels on controls. So the first step you take is to look how something like this is represented

Control[{{u, 1, "Label"}, 0, 2}]

Go to the output slider with the cursor and press Ctrl+Shift+E to see its box-form. There, you will notice that it uses a simple Grid to attach the label to the control. That can be used with your InputField as well

Panel[
 Grid[{{"My Label", InputField[x]}}]
]

Mathematica graphics

halirutan
  • 112,764
  • 7
  • 263
  • 474
  • Tried to implement your suggestion much appreciated, didnt know that you can see the box-form with this combination! However I did encounter some problems – julsto Jun 26 '18 at 15:16