Packages
surface
0.9.0
0.12.3
0.12.2
0.12.1
0.12.0
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.0
0.9.5
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.1
0.1.0
0.1.0-alpha.2
0.1.0-alpha.1
0.1.0-alpha.0
A component based library for Phoenix LiveView
Current section
Files
Jump to
Current section
Files
lib/surface/components/form/inputs.ex
defmodule Surface.Components.Form.Inputs do
@moduledoc """
A wrapper for `Phoenix.HTML.Form.html.inputs_for/3`.
Additionally, adds the generated form instance that is returned by `inputs_for/3`
into the context, making it available to any child input.
"""
use Surface.Component
alias Surface.Components.Form
alias Surface.Components.Form.Field
import Phoenix.HTML.Form
@doc """
The parent form.
It should either be a `Phoenix.HTML.Form` emitted by `form_for` or an atom.
"""
prop form, :form, from_context: {Form, :form}
@doc """
An atom or string representing the field related to the child inputs.
"""
prop for, :any, from_context: {Field, :field}
@doc """
Extra options for `inputs_for/3`.
See `Phoenix.HTML.Form.html.inputs_for/4` for the available options.
"""
prop opts, :keyword, default: []
@doc "The code containing the input controls"
slot default, arg: %{form: :form, index: :integer}
data field, :any
def render(assigns) do
~F"""
{#for {f, index} <- Enum.with_index(inputs_for(@form, @for || @field, @opts))}
<#slot {@default, form: f, index: index} context_put={Form, form: f}/>
{/for}
"""
end
end