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

A field for handling a has_many or many_to_many relation.

This field can not be orderable or searchable.

Field-specific options

See Backpex.Field for general field options.

  • :display_field (atom/0) - Required. The field of the relation to be used for searching, ordering and displaying values.

  • :display_field_form (atom/0) - The field to be used to display form values.

  • :live_resource (atom/0) - The live resource of the association.

  • :link_assocs (boolean/0) - Whether to automatically generate links to the association items. The default value is true.

  • :options_query (function of arity 2) - 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.

    The default value is "Select options...".

  • :not_found_text (String.t/0) - The text to be displayed when no options are found.

    The default value is "No options found".

  • :query_limit - Limit passed to the query to fetch new items. Set to nil to have no limit. The default value is 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

assign_selected(socket)

validate_config!(field, live_resource)