Indy Forms - Simplify Your Forms

I see some ways to solve that issue in your example code: Awesome!!

def on_init(socket) do
  show_phone? = show_phone?(socket.assigns.row.contact_me)
  show_email? = show_email?(socket.assigns.row.contact_me)
  socket
  |> assign(:show_phone, show_phone?)
  |> assign(:show_email, show_email?)
end

defp show_phone?(value) do
  value in [:phone, :phone_email]
end

defp show_email?(value) do
  value in [:email, :phone_email]
end
<%= if @show_phone do %>
  <%= label f, :phone %>
  <%= text_input f, :phone %>
  <%= error_tag f, :phone %>
<% end %>

<%= if @show_email do %>
  <%= label f, :email %>
  <%= text_input f, :email %>
  <%= error_tag f, :email %>
<% end %>
1 Like