How to create dynamic form for inputs_for?

I’m creating some input helpers for my Phoenix form according to http://blog.plataformatec.com.br/2016/09/dynamic-forms-with-phoenix/, but I have no idea how to make one for inputs_for:

    <div class="form-group">
      <%= inputs_for f, :credential, fn cf -> %>
        <%= label cf, :password, "Password" %>
        <%= password_input cf, :password, class: "form-control" %>
        <%= error_tag cf, :password %>
      <% end %>
    </div>

Anyone have experience?

All right, it’s actually very easy, here’s my answer to my question:

  def inputs(form, field, sub_field) do
    inputs_for(form, field, [], fn fp ->
      input(fp, sub_field)
    end)
  end

And I can use it in my template like this:

<%= inputs f, :credential, :password %>
2 Likes