# Input Matrix using Table and InputField [duplicate]

I'm trying to make a square matrix of InputFields, where the size is dependent on what the user chooses. Each cell should be independent of each other.

Here's what I tried:

Clear["Global*"]
dimension = 3;
inputA = Partition[Table[
InputField[Dynamic[a[i], Function[If[# =!= Null && IntegerQ[#], a[i] = #]]],
Number, FieldSize -> 4],
{i, dimension^2}], dimension];


But when I run this, all of the cells are assigned as one variable, so if I put in a number in any of the cells, the rest of the cells auto-populate to that number. I am lost as to what I'm doing wrong here. Why doesn't the table assign the cells as a[1], a[2], and so on?

dim = 3; a = ConstantArray[0, dim^2];
`