AshFormBuilder.Transformers.GenerateFormModule (AshFormBuilder v0.2.0)

View Source

Generates a Resource.Form helper module at compile time for every resource that declares a form block.

The generated module provides:

  • for_action/2 — creates an AshPhoenix.Form for the declared action,
                   pre-configured with all nested form definitions.
  • for_create/1 — alias when the declared action is a create action.
  • for_update/2 — alias when the declared action is an update action;
                   first arg is the existing record.
  • schema/0 — returns the inferred form schema as a list of field maps.
  • nested_forms/0 — returns the AshPhoenix.Form :forms configuration.

Domain Code Interface Integration

When used with Domain Code Interfaces, the form helpers work seamlessly:

# Domain automatically generates form_to_<action> functions
defmodule MyApp.Billing do
  use Ash.Domain

  resources do
    resource MyApp.Billing.Clinic do
      define :form_to_create_clinic, action: :create
      define :form_to_update_clinic, action: :update
    end
  end
end

# In your LiveView:
form = MyApp.Billing.Clinic.Form.for_create(actor: socket.assigns.current_user)

Example

# Create form in a LiveView mount:
form = MyApp.Post.Form.for_create(actor: current_user)
{:ok, assign(socket, form: form)}

# Then in the template:
<.live_component module={AshFormBuilder.FormComponent}
  id="create-post"
  form={@form} />

Summary

Functions

after_compile?()

Callback implementation for Spark.Dsl.Transformer.after_compile?/0.