AshFormBuilder.FormComponent (AshFormBuilder v0.2.0)

View Source

A self-contained Phoenix LiveComponent that renders and manages an AshPhoenix.Form based on the AshFormBuilder DSL declared on a resource.

Usage

<.live_component
  module={AshFormBuilder.FormComponent}
  id="create-post"
  resource={MyApp.Post}
  form={@form}
/>

The parent LiveView creates the initial form (the generated Resource.Form helper does this for you):

form = MyApp.Post.Form.for_create(actor: current_user)
{:ok, assign(socket, form: form)}

On successful submit the component sends a message to the parent process:

def handle_info({:form_submitted, MyApp.Post, post}, socket) do
  {:noreply, push_navigate(socket, to: ~p"/posts/#{post}")}
end

Assigns

assigntyperequireddescription
:resourcemoduleyesThe Ash resource module
:formPhoenix.HTML.FormyesForm produced by to_form/1
:idstringyesLiveComponent id
:on_submit(result -> any)noCallback instead of send/2
:submit_labelstringnoOverride the DSL submit label