View Source Backpex.Fields.HasMany (Backpex v0.8.1)

A field for handling a has_many or many_to_many relation.

This field can not be orderable or searchable.

Options

  • :display_field - The field of the relation to be used for searching, ordering and displaying values.
  • :display_field_form - Optional field to be used to display form values.
  • :live_resource - The live resource of the association.
  • :link_assocs - Whether to automatically generate links to the association items. Defaults to true.
  • :options_query - Manipulates the list of available options in the multi select. Defaults to fn (query, _field) -> query end which returns all entries.
  • :prompt - The text to be displayed when no options are selected or function that receives the assigns. Defaults to "Select options...".
  • :not_found_text - The text to be displayed when no options are found. Defaults to "No options found".
  • :query_limit - Optional limit passed to the query to fetch new items. Set to nil to have no limit. Defaults to 10.

Example

@impl Backpex.LiveResource
def fields do
[
  posts: %{
    module: Backpex.Fields.HasMany,
    label: "Posts",
    display_field: :title,
    options_query: &where(&1, [user], user.role == :admin),
    live_resource: DemoWeb.PostLive
  }
]
end

Summary

Functions