fix(rover-planning): keep only_known_good checked across phx-change events
The hidden 'false' shadow input was rendered after the checkbox, so when both were submitted the 'false' value overwrote the checkbox 'true' in the resulting params map. Move the hidden input before the checkbox so the checked value wins (matching the core_components checkbox pattern).
This commit is contained in:
parent
3c9fbcdec6
commit
eca463add1
2 changed files with 26 additions and 1 deletions
|
|
@ -217,6 +217,7 @@ defmodule MicrowavepropWeb.RoverPlanningLive.Form do
|
|||
</div>
|
||||
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="hidden" name="mission[only_known_good]" value="false" />
|
||||
<input
|
||||
type="checkbox"
|
||||
name="mission[only_known_good]"
|
||||
|
|
@ -224,7 +225,6 @@ defmodule MicrowavepropWeb.RoverPlanningLive.Form do
|
|||
checked={Phoenix.HTML.Form.normalize_value("checkbox", @form[:only_known_good].value)}
|
||||
class="checkbox checkbox-primary"
|
||||
/>
|
||||
<input type="hidden" name="mission[only_known_good]" value="false" />
|
||||
<span>
|
||||
Only check against known good locations
|
||||
<span class="text-xs opacity-70 block">
|
||||
|
|
|
|||
|
|
@ -83,6 +83,31 @@ defmodule MicrowavepropWeb.RoverPlanningLiveTest do
|
|||
live(conn, ~p"/rover-planning/new")
|
||||
end
|
||||
|
||||
test "typing into the form does not flip the only_known_good checkbox", %{conn: conn} do
|
||||
user = AccountsFixtures.user_fixture()
|
||||
conn = log_in_user(conn, user)
|
||||
{:ok, lv, _html} = live(conn, ~p"/rover-planning/new")
|
||||
|
||||
html =
|
||||
lv
|
||||
|> form("#mission-form",
|
||||
mission: %{
|
||||
name: "Some name",
|
||||
band_mhz: "10000",
|
||||
rover_height_ft: "8.0",
|
||||
station_height_ft: "30.0",
|
||||
only_known_good: "true",
|
||||
stations: %{"0" => %{input: ""}}
|
||||
}
|
||||
)
|
||||
|> render_change()
|
||||
|
||||
# The default-checked box must STILL be checked after a phx-change.
|
||||
# Hidden "false" + checkbox "true" with hidden first = checkbox wins.
|
||||
assert html =~
|
||||
~s(name="mission[only_known_good]" value="true" checked)
|
||||
end
|
||||
|
||||
test "logged-in user can create a mission with a callsign-input station",
|
||||
%{conn: conn} do
|
||||
user = AccountsFixtures.user_fixture()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue