fix: preserve NetBox url/api_token in netbox_config across re-renders

Sync direction button clicks (phx-click) triggered a LiveView re-render
that reset the url and api_token inputs to their saved DB values, wiping
any unsaved typed text. Fix by tracking url and api_token in @netbox_config
so they survive click-triggered re-renders.
This commit is contained in:
Graham McIntire 2026-03-12 14:25:08 -05:00
parent 4246ffa7a0
commit f980e9eb6d
No known key found for this signature in database
2 changed files with 8 additions and 2 deletions

View file

@ -442,6 +442,8 @@ defmodule ToweropsWeb.Org.SettingsLive do
socket =
if socket.assigns.configuring == "netbox" do
assign(socket, :netbox_config, %{
"url" => Map.get(params, "url", ""),
"api_token" => Map.get(params, "api_token", ""),
"sync_direction" => Map.get(params, "sync_direction", "pull"),
"sync_devices" => Map.get(params, "sync_devices", "true") == "true",
"sync_sites" => Map.get(params, "sync_sites", "true") == "true",
@ -921,6 +923,8 @@ defmodule ToweropsWeb.Org.SettingsLive do
defp default_netbox_config do
%{
"url" => "",
"api_token" => "",
"sync_direction" => "pull",
"sync_devices" => true,
"sync_sites" => true,
@ -936,6 +940,8 @@ defmodule ToweropsWeb.Org.SettingsLive do
defp load_netbox_config(%Integration{credentials: creds}) when is_map(creds) do
%{
"url" => Map.get(creds, "url", ""),
"api_token" => Map.get(creds, "api_token", ""),
"sync_direction" => Map.get(creds, "sync_direction", "pull"),
"sync_devices" => Map.get(creds, "sync_devices", true),
"sync_sites" => Map.get(creds, "sync_sites", true),

View file

@ -1204,7 +1204,7 @@
<input
type="text"
name="integration[url]"
value={get_credential(@integrations["netbox"], "url")}
value={@netbox_config["url"]}
placeholder="https://netbox.example.com"
autocomplete="off"
class="block w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-indigo-500 focus:ring-indigo-500 dark:border-white/10 dark:bg-gray-800 dark:text-white dark:placeholder-gray-500"
@ -1217,7 +1217,7 @@
<input
type="password"
name="integration[api_token]"
value={get_credential(@integrations["netbox"], "api_token")}
value={@netbox_config["api_token"]}
placeholder={t("Enter your NetBox API token")}
autocomplete="off"
class="block w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-indigo-500 focus:ring-indigo-500 dark:border-white/10 dark:bg-gray-800 dark:text-white dark:placeholder-gray-500"