Gauge fixing and transformation

given the gauge choice that div A = some value/function.

i am completely fine that in the context of electromagnetism that by setting the divergence of this to be anything it has no effect on the curl of A e.g the magnetic field. as letting A= A + grad(f) means curl of grad(f) = 0

however in doing so you are changing the electric field given by phi - d(a)/dt

so why can you make this transformation and not change anything?

wikipedia says that by doing a transformation like this you have to do the transformation phi=phi-df/dt to keep the E field the same

But... how does simply setting div a = a value encompass this second transformation

Electric and magnetic fields are related to potentials this way

$$\vec{B}=\vec{\nabla}\times\vec{A} \tag{1}$$ $$\vec{E}=-\vec{\nabla}\phi-\frac{\partial \vec{A}}{\partial t}. \tag{2}$$

A gauge transformation for those potentials is

$$\phi´=\phi-\frac{\partial f(\vec{x},t)}{\partial t} \tag{3}$$ $$\vec{A}´=\vec{A}+\vec{\nabla}f(\vec{x},t), \tag{4}$$

which leaves the fields $$(1)$$ and $$(2)$$ invariant.

Suppose that we have the potentials $$(\phi,\vec{A})$$, and we perform a gauge transformation $$(\phi,\vec{A})\rightarrow(\phi´,\vec{A}´)$$ so that the new potentials satisfy

$$\vec{\nabla}\cdot\vec{A}´=g(\vec{x},t).\tag{5}$$

Is this posible? That is, is there any $$f(\vec{x},t)$$ connecting $$(\phi,\vec{A})$$ and $$(\phi´,\vec{A}´)$$ through $$(3)$$ and $$(4)$$ that makes $$\vec{A}´$$ satisfy $$(5)$$?.

Taking the divergence of $$(4)$$ gives us

$$g(\vec{x},t)=\vec{\nabla}\cdot\vec{A}+\nabla ^2f(\vec{x},t),$$ which is Poisson's equation for $$f(\vec{x},t)$$, and the solution (appart from solutions to the homogeneous equation, i.e. Laplace's equation) is

$$f(\vec{x},t)=-\int d^3\vec{x}'\frac{g(\vec{x}')-\vec{\nabla}'\cdot\vec{A}}{4\pi|\vec{x}-\vec{x}'|},\tag{6}$$

where $$\vec{\nabla}'$$ indicates derivatives with respect to $$x', y', z'$$.

So our new vector potential $$\vec{A}´$$ will satisfy $$(5)$$ and will describe the same fields that our old potential did.

Edit:

Note that $$\phi$$ must also be transformed via $$(3)$$ with the same $$f$$ in order to keep the fields invariant.