View Source Backpex.ItemAction behaviour (Backpex v0.8.1)
Behaviour implemented by all item actions.
Summary
Callbacks
cancel button label
The changeset to be used in the resource action. It may be used to validate form inputs.
This text is being displayed in the confirm dialog.
Confirm button label
A list of fields to be displayed in the item action. See Backpex.Field
. In addition you have to provide
a type
for each field in order to support changeset generation.
Performs the action. It takes the socket and the casted and validated data (received from Ecto.Changeset.apply_action/2
).
Action icon
Initial change. The result will be passed to changeset/3
in order to generate a changeset.
Action label (Show label on hover)
Functions
Defines Backpex.ItemAction
behaviour and provides default implementations.
Callbacks
cancel button label
@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.
This text is being displayed in the confirm dialog.
There won't be any confirmation when this function is not defined.
Confirm button label
@callback fields() :: list()
A list of fields to be displayed in the item action. See Backpex.Field
. In addition you have to provide
a type
for each field in order to support changeset generation.
The following fields are currently not supported:
@callback handle( socket :: Phoenix.LiveView.Socket.t(), items :: [map()], params :: map() | struct() ) :: {:noreply, Phoenix.LiveView.Socket.t()} | {:reply, map(), Phoenix.LiveView.Socket.t()}
Performs the action. It takes the socket and the casted and validated data (received from Ecto.Changeset.apply_action/2
).
@callback icon(assigns :: map(), item :: struct()) :: %Phoenix.LiveView.Rendered{ caller: term(), dynamic: term(), fingerprint: term(), root: term(), static: term() }
Action icon
@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 item actions. If this function
is not provided a changeset will be generated automatically based on the provided types in fields/0
.
Action label (Show label on hover)
Functions
Defines Backpex.ItemAction
behaviour and provides default implementations.