I have written two functions one for creating list of InputField
Options[UserInputField] :=
{
enableList -> {False, True, True},
backgroundList -> Table[White, {3}, {4}],
fieldHintList -> {Table["Value1", {4}], Table["Value2", {4}], Table["Value3", {4}]},
toolTipList -> {Table["Value1", {4}], Table["Value2", {4}],Table["Value3", {4}]}
};
UserInputField[inputValueList1_, OptionsPattern[]] :=
Module[{inputValueList = inputValueList1},
{
Table[
With[{i = i, j = j},
Tooltip[InputField[Dynamic[inputValueList[[i, j]]], Number,
Enabled -> OptionValue[enableList][[i]],
ContinuousAction -> True, ImageSize -> {100, 40},
Alignment -> Center,
Background -> OptionValue[backgroundList][[i, j]],
FieldHint -> OptionValue[fieldHintList][[i, j]],
FieldHintStyle -> Directive[Black, Bold, 15]],
OptionValue[toolTipList][[i, j]]]], {i,
Length[inputValueList]}, {j, Length[inputValueList[[i]]]}],
Dynamic[inputValueList]
}
]
and another for logic.
logic[inputValueList1_] :=
Module[
{
inputValueList = inputValueList1,
backgroundList = Table[White, {3}, {4}],
fieldHintList = {Table["Value1", {4}], Table["Value2", {4}],
Table["Value3", {4}]},
toolTipList = {Table["Value1", {4}], Table["Value2", {4}],
Table["Value3", {4}]}
},
{Table[
With[
{i = i, j = j},
(
If[
i == 1,
(
If[
UnsameQ[inputValueList[[i + 1, j]], Null] &&
UnsameQ[inputValueList[[i + 2, j]], Null],
(
If[
(
(50 >= inputValueList[[i + 1, j]] >= 0) &&
(100 >= inputValueList[[i + 2, j]] >= 1)
),
(
inputValueList[[i, j]] = (inputValueList[[i + 1, j]] +
inputValueList[[i + 2, j]]);
),
(
If[
(50 >= inputValueList[[i + 1, j]] >= 0),
(
""
),
(
backgroundList[[i + 1, j]] = Red;
fieldHintList[[i + 1, j]] = "!";
toolTipList[[i + 1, j]] = "NotInRange";
)
];
If[
(100 >= inputValueList[[i + 2, j]] >= 1),
(
""
),
(
backgroundList[[i + 2, j]] = Red;
fieldHintList[[i + 2, j]] = "!";
toolTipList[[i + 2, j]] = "NotInRange";
)
]
)
]
)
];
)
]
)
],
{i, Length[inputValueList]}, {j, Length[inputValueList[[i]]]}
];,
Dynamic[inputValueList],
Dynamic[backgroundList],
Dynamic[fieldHintList],
Dynamic[toolTipList]
}
];
Here I made interaction between those functions.
inputValueList = Table[Null, {3}, {4}];
userBackgroundList = Table[White, {3}, {4}];
userFieldHintList = {Table["Value1", {4}], Table["Value2", {4}],Table["Value3", {4}]};
userToolTipList = {Table["Value1", {4}], Table["Value2", {4}],Table["Value3", {4}]};
{
userField =
UserInputField[inputValueList, backgroundList -> userBackgroundList,
fieldHintList -> userFieldHintList,
toolTipList -> userToolTipList],
userLogic = Dynamic[logic[Setting[userField[[2]]]]];,
Dynamic[inputValueList = Setting[userLogic][[2]]],
Dynamic[userBackgroundList = Setting[userLogic][[3]]],
Dynamic[userFieldHintList = Setting[userLogic][[4]]],
Dynamic[userToolTipList = Setting[userLogic][[5]]]
}
As you can see the output, there is three rows of InputField
each row contains four InputField
.First row of InputField
's is disabled and remaining two rows are enabled.
When user enter value in second row first column InputField
and third row first column InputField
dynamically the addition of two values should be shown in First row first column InputField
. If the entered value is not in limit, set Background
as Red color
, Fieldhint
as !
and Tooltip
as NotInRange
for respective InputField
, but here it is not happening.
The value of InputField
being calculated but not displayed in First row InputField
. Background
, Fieldhint
and Tooltip
for the wrong value is assigned for corresponding InputField
but also not displayed. I tried to put UserInputField function in Dynamic[]
funciton but it's not working.