AshFormBuilder.Info (AshFormBuilder v0.2.0)

View Source

Introspection helpers for AshFormBuilder DSL data.

Works on both compiled resource modules and in-progress dsl_state maps (the latter is used inside Spark transformers).

Auto-inference

effective_fields/1 and effective_entities/1 are the preferred runtime accessors. They merge auto-inferred fields (derived from the action's accept list via AshFormBuilder.TypeInference) with any explicit DSL overrides. Explicit declarations win on a per-field basis.

The lower-level form_fields/1 and form_entities/1 return only the explicitly declared DSL entities — useful inside transformers where Ash.Resource.Info is not yet available.

Summary

Functions

Builds the AshPhoenix.Form :forms keyword list from the nested entities.

Returns all effective form entities: effective_fields/1 followed by the NestedForm structs declared in the DSL.

Returns the effective list of Field structs for the form action.

form DSL entities

Returns the configured :action option, or nil if no form block.

The Ash action this form targets, e.g. :create or :update.

Enable creatable combobox for all many_to_many relationships. Individual fields can override this.

Enable creatable combobox for all many_to_many relationships. Individual fields can override this.

Default action to use for creating new items in creatable comboboxes.

Default action to use for creating new items in creatable comboboxes.

All DSL entities in declaration order (mix of Field and NestedForm structs).

Custom ordering for fields. Fields listed first appear first. Fields not listed appear after in default order.

Custom ordering for fields. Fields listed first appear first. Fields not listed appear after in default order.

Only the top-level Field structs declared in the DSL.

HTML id attribute for the <form> element.

HTML id attribute for the <form> element.

Returns the configured :form_id, or nil.

Fields to exclude from auto-inference. Use this to hide fields without writing full field blocks.

Fields to exclude from auto-inference. Use this to hide fields without writing full field blocks.

Whether to include :inserted_at and :updated_at fields. Set to true if you need timestamp inputs.

Whether to include :inserted_at and :updated_at fields. Set to true if you need timestamp inputs.

Override the auto-generated helper module name (default: Resource.Form).

Override the auto-generated helper module name (default: Resource.Form).

Returns the override :module option, or nil (generator uses Resource.Form by default).

Only the NestedForm structs declared in the DSL.

Returns the configured :submit_label, defaulting to "Submit".

Label for the submit button.

Returns the configured :wrapper_class, defaulting to "space-y-4".

CSS class applied to the fields wrapper <div>.

True when the resource has a form block with an action set.

Functions

build_nested_forms_config(resource_or_dsl)

Builds the AshPhoenix.Form :forms keyword list from the nested entities.

Used by the generated Resource.Form.for_action/2 helper so callers never have to hand-write the nested form configuration.

effective_entities(resource)

@spec effective_entities(module()) :: list()

Returns all effective form entities: effective_fields/1 followed by the NestedForm structs declared in the DSL.

This is the preferred accessor for rendering — it gives a complete, ordered list of what to render without requiring explicit field declarations.

Only call this on a compiled resource module.

effective_fields(resource)

@spec effective_fields(module()) :: [AshFormBuilder.Field.t()]

Returns the effective list of Field structs for the form action.

Fields are produced by auto-inferring from the action's accept list, then applying explicit DSL declarations as overrides (explicit wins per field name).

Any DSL field whose name is not in the inferred list is appended at the end, allowing you to add argument fields not in accept.

Only call this on a compiled resource module, not on a dsl_state map.

form(dsl_or_extended)

@spec form(dsl_or_extended :: module() | map()) :: [struct()]

form DSL entities

form_action(dsl_or_extended)

@spec form_action(dsl_or_extended :: module() | map()) :: {:ok, atom()} | :error

Returns the configured :action option, or nil if no form block.

form_action!(dsl_or_extended)

@spec form_action!(dsl_or_extended :: module() | map()) :: atom() | no_return()

The Ash action this form targets, e.g. :create or :update.

form_creatable(dsl_or_extended)

@spec form_creatable(dsl_or_extended :: module() | map()) :: {:ok, boolean()} | :error

Enable creatable combobox for all many_to_many relationships. Individual fields can override this.

form_creatable!(dsl_or_extended)

@spec form_creatable!(dsl_or_extended :: module() | map()) :: boolean() | no_return()

Enable creatable combobox for all many_to_many relationships. Individual fields can override this.

form_create_action(dsl_or_extended)

@spec form_create_action(dsl_or_extended :: module() | map()) ::
  {:ok, atom()} | :error

Default action to use for creating new items in creatable comboboxes.

form_create_action!(dsl_or_extended)

@spec form_create_action!(dsl_or_extended :: module() | map()) :: atom() | no_return()

Default action to use for creating new items in creatable comboboxes.

form_entities(resource_or_dsl)

All DSL entities in declaration order (mix of Field and NestedForm structs).

form_field_order(dsl_or_extended)

@spec form_field_order(dsl_or_extended :: module() | map()) ::
  {:ok, [atom()]} | :error

Custom ordering for fields. Fields listed first appear first. Fields not listed appear after in default order.

form_field_order!(dsl_or_extended)

@spec form_field_order!(dsl_or_extended :: module() | map()) :: [atom()] | no_return()

Custom ordering for fields. Fields listed first appear first. Fields not listed appear after in default order.

form_fields(resource_or_dsl)

Only the top-level Field structs declared in the DSL.

form_form_id(dsl_or_extended)

@spec form_form_id(dsl_or_extended :: module() | map()) :: {:ok, String.t()} | :error

HTML id attribute for the <form> element.

form_form_id!(dsl_or_extended)

@spec form_form_id!(dsl_or_extended :: module() | map()) :: String.t() | no_return()

HTML id attribute for the <form> element.

form_html_id(resource_or_dsl)

Returns the configured :form_id, or nil.

form_ignore_fields(dsl_or_extended)

@spec form_ignore_fields(dsl_or_extended :: module() | map()) ::
  {:ok, [atom()]} | :error

Fields to exclude from auto-inference. Use this to hide fields without writing full field blocks.

form_ignore_fields!(dsl_or_extended)

@spec form_ignore_fields!(dsl_or_extended :: module() | map()) ::
  [atom()] | no_return()

Fields to exclude from auto-inference. Use this to hide fields without writing full field blocks.

form_include_timestamps(dsl_or_extended)

@spec form_include_timestamps(dsl_or_extended :: module() | map()) ::
  {:ok, boolean()} | :error

Whether to include :inserted_at and :updated_at fields. Set to true if you need timestamp inputs.

form_include_timestamps!(dsl_or_extended)

@spec form_include_timestamps!(dsl_or_extended :: module() | map()) ::
  boolean() | no_return()

Whether to include :inserted_at and :updated_at fields. Set to true if you need timestamp inputs.

form_module(dsl_or_extended)

@spec form_module(dsl_or_extended :: module() | map()) :: {:ok, atom()} | :error

Override the auto-generated helper module name (default: Resource.Form).

form_module!(dsl_or_extended)

@spec form_module!(dsl_or_extended :: module() | map()) :: atom() | no_return()

Override the auto-generated helper module name (default: Resource.Form).

form_module_override(resource_or_dsl)

Returns the override :module option, or nil (generator uses Resource.Form by default).

form_nested(resource_or_dsl)

Only the NestedForm structs declared in the DSL.

form_options(dsl_or_extended)

@spec form_options(dsl_or_extended :: module() | map()) :: %{
  required(atom()) => any()
}

form DSL options

Returns a map containing the and any configured or default values.

form_submit_label(dsl_or_extended)

@spec form_submit_label(dsl_or_extended :: module() | map()) ::
  {:ok, String.t()} | :error

Returns the configured :submit_label, defaulting to "Submit".

form_submit_label!(dsl_or_extended)

@spec form_submit_label!(dsl_or_extended :: module() | map()) ::
  String.t() | no_return()

Label for the submit button.

form_wrapper_class(dsl_or_extended)

@spec form_wrapper_class(dsl_or_extended :: module() | map()) ::
  {:ok, String.t()} | :error

Returns the configured :wrapper_class, defaulting to "space-y-4".

form_wrapper_class!(dsl_or_extended)

@spec form_wrapper_class!(dsl_or_extended :: module() | map()) ::
  String.t() | no_return()

CSS class applied to the fields wrapper <div>.

has_form?(resource_or_dsl)

True when the resource has a form block with an action set.