Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change form fields from hidden to text for liveview testing ease of use #50

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/live_select/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule LiveSelect.Component do
use Phoenix.LiveComponent

import Phoenix.HTML.Form,
only: [text_input: 3, hidden_input: 3]
only: [text_input: 3]

import LiveSelect.ClassUtil

Expand Down
10 changes: 6 additions & 4 deletions lib/live_select/component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@
<% end %>
</div>
<%= if @mode == :single do %>
<%= hidden_input(@field.form, @field.field,
<%= text_input(@field.form, @field.field,
disabled: @disabled,
class: "single-mode",
class: "single-mode hidden",
value: value(@selection)
) %>
<% else %>
<!-- TODO: the stuff below could be replaced with a single hidden, readonly multiselect, but updates don't quite work. So we resort to hidden inputs for now -->
<%= if Enum.empty?(@selection) do %>
<input
type="hidden"
type="text"
class="hidden"
name={"#{@field.form.name}[#{@field.field}_empty_selection]"}
id={"#{@field.id}_empty_selection"}
disabled={@disabled}
Expand All @@ -81,7 +82,8 @@
<% end %>
<%= for {value, idx} <- values(@selection) |> Enum.with_index() do %>
<input
type="hidden"
type="text"
class="hidden"
name={@field.name <> "[]"}
id={@field.id <> "_#{idx}"}
disabled={@disabled}
Expand Down
2 changes: 1 addition & 1 deletion test/support/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ defmodule LiveSelect.TestHelpers do
|> Enum.map(&{&1.value, &1[:tag_label] || &1.label})
|> Enum.unzip()

assert Floki.attribute(html, "#{@selectors[:container]} input[type=hidden]", "value") ==
assert Floki.attribute(html, "#{@selectors[:container]} input[class=hidden]", "value") ==
encode_values(values)

assert html
Expand Down