AshFormBuilder.FormComponent (AshFormBuilder v0.2.1)

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

File Upload Support

Fields declared with type: :file_upload are automatically wired to Phoenix LiveView's upload lifecycle. Configure uploads via opts:

field :avatar do
  type :file_upload
  opts [upload: [cloud: MyApp.Cloud, max_entries: 1, accept: ~w(.jpg .png)]]
end

On submit, entries are consumed and stored via the configured Buckets.Cloud module before the Ash action is called.