I’m trying to provide a default value (which is a name retrieved from a DB) to an input tag. When the form is mounted, the default value in the “name” field input box is populated as expected. Then the user enters a different name to replace the default value, and it changes with no problem. However, when the user then enters a value to the other input (“Code” field), the Name field goes back to the initial default value. How can I make the form keep the user input (after the form validation)? Or is there a better way to provide a default input value?
<.form :let={f} phx-change="validate">
<.input field={{f, :name}} type="text" label="Name" value={@dynamic_default_name}>
<.input field={{f, :code}} type="text" label="Code" >
</.form>
def handle_event("validate", %{"form" => form_params}, socket) do
form = AshPhoenix.Form.validate(socket.assigns.form, form_params)
socket
|> assign(:form, form)
|> noreply()
end