AshPhoenix (ash_phoenix v0.4.1) View Source

See the readme for the current state of the project

Link to this section Summary

Functions

A utility to support "add" buttons on embedded types used in forms.

A utility to support "add" buttons on relationships used in forms.

A utility to support "remove" buttons on embedded types used in forms.

A utility to support "remove" buttons on relationships used in forms.

Link to this section Functions

Link to this function

add_embed(query, path, outer_form_name, add \\ %{})

View Source

A utility to support "add" buttons on embedded types used in forms.

To use, simply pass in the form name of the embedded form as well as the name of the primary/outer form.

# In your template, inside a form called `:change`
<button phx-click="append_thing" phx-value-path={{form.path}}>
</button>

# In the view/component

def handle_event("append_thing", %{"path" => path}, socket) do
  changeset = add_embed(socket.assigns.changeset, path, "change")
  {:noreply, assign(socket, changeset: changeset)}
end

You can also pass a specific value to be added, to seed the changes in a customized way. By default, %{} is used.

Link to this function

add_related(changeset, path, outer_form_name, opts \\ [])

View Source

Specs

A utility to support "add" buttons on relationships used in forms.

To use, simply pass in the form name of the relationship form as well as the name of the primary/outer form.

# In your template, inside a form called `:change`
<button phx-click="append_thing" phx-value-path={{form.path}}>
</button>

# In the view/component

def handle_event("append_thing", %{"path" => path}, socket) do
  changeset = add_related(socket.assigns.changeset, path, "change")
  {:noreply, assign(socket, changeset: changeset)}
end

Options

* `:add` - the value to add to the relationship, defaults to `%{}` The default value is `%{}`.
  • :relationship - The relationship being updated, in case it can't be determined from the path

  • :id - The value that should be in meta[:id] in the manage changeset opts. Defaults to the relationship name. This only needs to be set if an id is also provided for inputs_for.

Link to this function

hiding_errors?(changeset)

View Source
Link to this function

remove_embed(changeset, path, outer_form_name)

View Source

A utility to support "remove" buttons on embedded types used in forms.

To use, simply pass in the form name of the embedded form as well as the name of the primary/outer form.

# In your template, inside a form called `:change`
<button phx-click="remove_thing" phx-value-path={{form.path}}>
</button>

# In the view/component

def handle_event("remove_thing", %{"path" => path}, socket) do
  changeset = remove_embed(socket.assigns.changeset, path, "change")
  {:noreply, assign(socket, changeset: changeset)}
end
Link to this function

remove_related(changeset, path, outer_form_name, opts \\ [])

View Source

Specs

A utility to support "remove" buttons on relationships used in forms.

To use, simply pass in the form name of the related form as well as the name of the primary/outer form.

# In your template, inside a form called `:change`
<button phx-click="remove_thing" phx-value-path={{form.path}}>
</button>

# In the view/component

def handle_event("remove_thing", %{"path" => path}, socket) do
  {record, changeset} = remove_related(socket.assigns.changeset, path, "change")
  {:noreply, assign(socket, record: record, changeset: changeset)}
end

Options

* `:add` - the value to add to the relationship, defaults to `%{}` The default value is `%{}`.
  • :relationship - The relationship being updated, in case it can't be determined from the path

  • :id - The value that should be in meta[:id] in the manage changeset opts. Defaults to the relationship name. This only needs to be set if an id is also provided for inputs_for.

Link to this function

to_form_error(exception)

View Source
Link to this function

transform_errors(changeset, transform_errors)

View Source