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}")}
endAssigns
| assign | type | required | description |
|---|---|---|---|
:resource | module | yes | The Ash resource module |
:form | Phoenix.HTML.Form | yes | Form produced by to_form/1 |
:id | string | yes | LiveComponent id |
:on_submit | (result -> any) | no | Callback instead of send/2 |
:submit_label | string | no | Override the DSL submit label |