@@ -17,8 +17,8 @@ defmodule PetalComponents.Field do
1717
1818 It's possible to support custom field types by using the `type={%{type="SomeCustomType", other_assigns...}}.`
1919 In order to define a custom field, a module that implements `PetalComponents.Field.Extension` behavior
20- needs to be implemented. Its `render/1` function needs to accept an assigns that will
21- be used for passing a map obtained by merging the assigns passed to this field with the
20+ needs to be implemented. Its `render/1` function needs to accept an assigns argument
21+ that will be used for passing a map obtained by merging the assigns given to this field with the
2222 assigns in the `other_assigns...` passed in the `type` field.
2323 See the example below:
2424
@@ -32,7 +32,7 @@ defmodule PetalComponents.Field do
3232 @impl true
3333 def render(assigns) do
3434 ~H'''
35- <input id={@id} field ={@name} value={@value} class={@class} datalist={@datalist} {@rest}/>
35+ <input id={@id} name ={@name} value={@value} class={@class} datalist={@datalist} {@rest}/>
3636 <datalist id={@datalist}>
3737 <option :for={{value, option} <- @options} value={value}><%= option %></option>
3838 </datalist>
@@ -643,7 +643,7 @@ defmodule PetalComponents.Field do
643643
644644 module = field_type_extension ( type )
645645 assigns = assign ( assigns , :class , [ assigns . class , get_class_for_type ( module , type ) ] )
646- { assigns , body } = render_body ( module , assigns )
646+ body = render_body ( module , assigns )
647647 assigns = assign ( assigns , :body , body )
648648 ~H"""
649649 < . field_wrapper id = { "#{ @ id } -wr" } errors = { @ errors } name = { @ name } class = { @ wrapper_class } no_margin = { @ no_margin } >
@@ -824,32 +824,23 @@ defmodule PetalComponents.Field do
824824 end
825825 end
826826
827- @ spec render_body ( nil | atom ( ) , map ( ) ) :: { map ( ) , Phoenix.LiveView.Rendered . t ( ) }
827+ @ spec render_body ( nil | atom ( ) , map ( ) ) :: Phoenix.LiveView.Rendered . t ( )
828828
829829 defp render_body ( nil , assigns ) do
830- {
831- assigns ,
832- ~H"""
833- < input
834- type = { @ type }
835- name = { @ name }
836- id = { @ id }
837- value = { Phoenix.HTML.Form . normalize_value ( @ type , @ value ) }
838- class = { @ class }
839- required = { @ required }
840- { @ rest }
841- />
842- """
843- }
830+ ~H"""
831+ < input
832+ type = { @ type }
833+ name = { @ name }
834+ id = { @ id }
835+ value = { Phoenix.HTML.Form . normalize_value ( @ type , @ value ) }
836+ class = { @ class }
837+ required = { @ required }
838+ { @ rest }
839+ />
840+ """
844841 end
845842
846- defp render_body ( mod , assigns ) do
847- rest = assigns [ :rest ] || % { }
848- { extensions , rest } = Map . pop ( rest , :extension , % { } )
849- new_assigns = assign ( assigns , :rest , rest )
850- assigns = Map . merge ( new_assigns , extensions )
851- { new_assigns , mod . render ( assigns ) }
852- end
843+ defp render_body ( mod , assigns ) , do: mod . render ( assigns )
853844
854845 # Note: we use persistent term to avoid the overhead of calling Application.get_env/2.
855846 # Here is the corresponding performance benchmark:
0 commit comments