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

A field for handling a belongs_to relation.

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) - Field to be used to display form values.

  • :live_resource (atom/0) - The live resource of the association. Used to generate links navigating to the association.

  • :options_query (function of arity 2) - Manipulates the list of available options in the select.

    Defaults to fn (query, _field) -> query end which returns all entries.

  • :prompt - The text to be displayed when no option is selected or function that receives the assigns.

  • :debounce - Timeout value (in milliseconds), "blur" or function that receives the assigns.

  • :throttle - Timeout value (in milliseconds) or function that receives the assigns.

Example

@impl Backpex.LiveResource
def fields do
[
  user: %{
    module: Backpex.Fields.BelongsTo,
    label: "Username",
    display_field: :username,
    options_query: &where(&1, [user], user.role == :admin),
    live_resource: DemoWeb.UserLive
  }
]
end

Summary

Functions

validate_config!(field, live_resource)