diff --git a/guides/actions/item-actions.md b/guides/actions/item-actions.md index e0529a57..2aabbd4d 100644 --- a/guides/actions/item-actions.md +++ b/guides/actions/item-actions.md @@ -119,6 +119,8 @@ Next, we need to implement the item action module. defmodule DemoWeb.ItemAction.SoftDelete do use BackpexWeb, :item_action + import Ecto.Changeset + alias Backpex.Resource @impl Backpex.ItemAction @@ -142,7 +144,7 @@ defmodule DemoWeb.ItemAction.SoftDelete do @required_fields ~w[reason]a @impl Backpex.ItemAction - def changeset(change, attrs) do + def changeset(change, attrs, _meta) do change |> cast(attrs, @required_fields) |> validate_required(@required_fields) @@ -151,6 +153,9 @@ defmodule DemoWeb.ItemAction.SoftDelete do @impl Backpex.ItemAction def label(_assigns), do: Backpex.translate("Delete") + @impl Backpex.ItemAction + def confirm(_assigns), do: "Why do you want to delete this item?" + @impl Backpex.ItemAction def confirm_label(_assigns), do: Backpex.translate("Delete") @@ -185,8 +190,8 @@ defmodule DemoWeb.ItemAction.SoftDelete do end ``` -In the above example, we define an item action to soft delete users. The item action will also ask the user for a reason before the user can be deleted. The user needs to fill out the reason field before the item action can be performed. The reason field is defined in the `fields/0` function. The `changeset/2` function is used to validate the user input. +In the above example, we define an item action to soft delete users. The item action will also ask the user for a reason before the user can be deleted. The user needs to fill out the reason field before the item action can be performed. The reason field is defined in the `fields/0` function. The `changeset/3` function is used to validate the user input. The `handle/3` function is called when the item action is triggered. The handle function receives the socket, the items that should be affected by the action, and the parameters that were submitted by the user. -By default an item action is triggered immediately when the user clicks on the corresponding icon in the resource table or in the show view, but an item actions also supports a confirmation dialog. To enable the confirmation dialog you need to implement the `confirm_label/1` function and return a string that will be displayed in the confirmation dialog. The confirmation dialog will be displayed when the user clicks on the icon in the resource table. \ No newline at end of file +By default an item action is triggered immediately when the user clicks on the corresponding icon in the resource table or in the show view, but an item actions also supports a confirmation dialog. To enable the confirmation dialog you need to implement the `confirm_label/1` function and return a string that will be displayed in the confirmation dialog. The confirmation dialog will be displayed when the user clicks on the icon in the resource table.