View Source Backpex.ResourceAction behaviour (Backpex v0.8.2)
Behaviour implemented by all resource action modules.
use Backpex.ResourceAction
When you
use Backpex.ResourceAction
, theBackpex.ResourceAction
module will set@behavior Backpex.ResourceAction
. In addition it will implement theBackpex.ResourceAction.init_change
function in order to generate a schemaless changeset by default.
Summary
Callbacks
The changeset to be used in the resource action. It may be used to validate form inputs.
A list of fields to be displayed in the resource action. See Backpex.Field
. In addition you have to provide
a type
for each field in order to support changeset generation.
The handle function for the corresponding action. It receives the socket and casted and validated data (received from Ecto.Changeset.apply_action/2
) and will be called when the form is valid and submitted.
Initial change. The result will be passed to changeset/3
in order to generate a changeset.
The label of the resource action. It will be the label for the resource action button.
The title of the resource action. It will be part of the page header and slide over title.
Callbacks
@callback changeset( change :: Ecto.Schema.t() | Ecto.Changeset.t() | {Ecto.Changeset.data(), Ecto.Changeset.types()}, attrs :: map(), metadata :: keyword() ) :: Ecto.Changeset.t()
The changeset to be used in the resource action. It may be used to validate form inputs.
Additional metadata is passed as a keyword list via the third parameter.
The list of metadata:
:assigns
- the assigns:target
- the name of theform
target that triggered the changeset call. Default tonil
if the call was not triggered by a form field.
@callback fields() :: list()
A list of fields to be displayed in the resource action. See Backpex.Field
. In addition you have to provide
a type
for each field in order to support changeset generation.
@callback handle(socket :: Phoenix.LiveView.Socket.t(), data :: map()) :: {:ok, binary()} | {:error, binary()}
The handle function for the corresponding action. It receives the socket and casted and validated data (received from Ecto.Changeset.apply_action/2
) and will be called when the form is valid and submitted.
It must return either {:ok, binary()}
or {:error, binary()}
@callback init_change(assigns :: map()) :: Ecto.Schema.t() | Ecto.Changeset.t() | {Ecto.Changeset.data(), Ecto.Changeset.types()}
Initial change. The result will be passed to changeset/3
in order to generate a changeset.
This function is optional and can be used to use changesets with schemas in resource actions. If this function
is not provided a changeset will be generated automatically based on the provided types in fields/0
.
@callback label() :: binary()
The label of the resource action. It will be the label for the resource action button.
@callback title() :: binary()
The title of the resource action. It will be part of the page header and slide over title.
Functions
Defines Backpex.ResourceAction
behaviour.
Gets the name of a resource action.