Upgrading to v0.2
View SourceBump Your Deps
Update Backpex to the latest version:
defp deps do
[
{:backpex, "~> 0.2.0"}
]
endPass assigns to init_change functions
We change the arity of the init_change/0 function to init_change/1 for resource and item actions.
The param will be the assigns. This adds more ways to construct an initial change.
If you had such a function in your resource or item action:
@impl Backpex.ItemAction
def init_change() do
# construct init change
endYou need to change it to this:
@impl Backpex.ItemAction
def init_change(_assigns) do
# construct init change
endChange arity of changeset functions
See Pull Request.
We are introducing a new way to pass metadata to changeset functions. Previously, we supported changeset functions with
different arities to optionally pass the assigns and target name to changesets.
With this release, we require the arity of all changeset functions you provide to be 3.
The metadata, previously passed as additional parameters, is now passed as a keyword list to changesets as the third parameter.
Currently we pass the following metadata to changesets:
:assigns- the assigns:target- the name of theformtarget that triggered the changeset call
When you previously had a LiveResource and Schema that looked like the following:
defmodule MyAppWeb.UserLive do
use Backpex.LiveResource,
...
update_changeset: &MyApp.User.changeset/2,
create_changeset: &MyApp.User.changeset/2,
end
defmodule MyApp.User do
...
def changeset(user, attrs) do
...
end
endYou have to change it to this:
defmodule MyAppWeb.UserLive do
use Backpex.LiveResource,
...
update_changeset: &MyApp.User.changeset/3,
create_changeset: &MyApp.User.changeset/3,
end
defmodule MyApp.User do
...
def changeset(user, attrs, metadata) do
# fetch assigns from metadata
assigns = Keyword.get(metadata, :assigns)
# fetch target from metadata
assigns = Keyword.get(metadata, :target)
...
end
endThis change applies to Resource and Item Actions as well.
For example:
defmodule MyApp.EmailResourceAction
use Backpex.ResourceAction
@impl Backpex.ResourceAction
def changeset(change, attrs, _metadata \\ []) do
...
end
endUpdate prompt option
With v0.2 we are updating the prompt option for fields. This affects to the following fields: BelongsTo, Select, HasMany, ManyToMany and MultiSelect.
The prompt option can be raw text or a function that takes the assigns and returns text.
We no longer support adding additional options.
If you previously had a field that looked like the following:
def fields do
[
user: %{
module: Backpex.Fields.BelongsTo,
label: "Author",
prompt: [key: "Please select an author", disabled: true],
...
},
]
endYou need to change it to the following:
def fields do
[
user: %{
module: Backpex.Fields.BelongsTo,
label: "Author",
prompt: "Please select an author",
...
},
]
end