# Upgrading to v0.14

## Bump Your Deps

Update Backpex to the latest version:

```elixir
defp deps do
  [
    {:backpex, "~> 0.14.0"}
  ]
end
```

## Filter callback functions have been changed

We now pass the assigns to the `query` and `options` filter callbacks. Therefore, the arity of these functions has changed.

- [`Backpex.Filter.query/3`]() -> `c:Backpex.Filter.query/4`
- [`Backpex.Filters.Boolean.options/0`]() -> `c:Backpex.Filters.Boolean.options/1`
- [`Backpex.Filters.MultiSelect.options/0`]() -> `c:Backpex.Filters.MultiSelect.options/1`
- [`Backpex.Filters.Select.options/0`]() -> `c:Backpex.Filters.Select.options/1`

If you have implemented any of the above callbacks, make sure to change your filters.

Before:

```elixir
defmodule MyAppWeb.Filters.PostPublished do
  use Backpex.Filters.Boolean

  @impl Backpex.Filter
  def label, do: "Published?"

  @impl Backpex.Filters.Boolean
  def options do
    [
      ...
    ]
  end
end
```

After:

```elixir
defmodule MyAppWeb.Filters.PostPublished do
  use Backpex.Filters.Boolean

  @impl Backpex.Filter
  def label, do: "Published?"

  @impl Backpex.Filters.Boolean
  def options(_assigns) do
    [
      ...
    ]
  end
end
```

## `input/1` component has been updated

We've updated the `Backpex.HTML.Form.input/1` component:

- `input_wrapper_class` attribute has been removed as it was used by the select input only
- new `error` class attribute to provide an error class to user over the defaults
- `legend` element was replaced by `div` element to align with Phoenix CoreComponents

If you use the `input/1` make sure to update your code to accommodate these breaking changes, particularly removing any references to the deprecated `input_wrapper_class` attribute.

## Item Actions with form require `changeset/3` callback

All item actions that define fields (basically all item actions with a form) must also implement `c:Backpex.ItemAction.changeset/3`. This is necessary for validating and casting the parameters received from the form.

```elixir
@impl Backpex.ItemAction
def changeset(change, attrs, _metadata) do
  change
  |> Ecto.Changeset.cast(attrs, [:field1, :field2])
  |> Ecto.Changeset.validate_required([:field1])
end
```

## `render_form_readonly/1` callback has been removed

We removed the `render_form_readonly/1` callback from fields. Instead, `readonly` must be handled directly in the `c:Backpex.Field.render_form/1` callback.

Make sure to update your custom fields accordingly. The `readonly` value will be available in the assigns, which will be `true` or `false`.

```elixir
@impl Backpex.Field
def render_form(%{readonly: true} = assigns) do
# Render readonly field
end

def render_form(%{readonly: false} = assigns) do
# Render editable field
end
```

See the [Readonly guide](readonly.md) for more details.
