View Source AshPhoenix.FilterForm (ash_phoenix v0.7.7)

Create a new filter form.

Options:

  • :params - Initial parameters to create the form with The default value is %{}.

  • :as - Set the parameter name for the form. The default value is "filter".

  • :transform_errors - Allows for manual manipulation and transformation of errors.
    If possible, try to implement AshPhoenix.FormData.Error for the error (if it as a custom one, for example). If that isn't possible, you can provide this function which will get the predicate and the error, and should return a list of ash phoenix formatted errors, e.g [{field :: atom, message :: String.t(), substituations :: Keyword.t()}]

  • :remove_empty_groups? - If true (the default), then any time a group would be made empty by removing a group or predicate, it is removed instead.
    An empty form can still be added, this only affects a group if its last component is removed. The default value is false.

Link to this section Summary

Functions

Adde a group to the filter.

Returns a flat list of all errors on all predicates in the filter.

Returns the list of available fields, which may be attributes, calculations, or aggregates.

Same as filter/2 but raises on errors.

Converts the form into a filter, and filters the provided query or resource with that filter.

Returns the minimal set of params (at the moment just strips ids) for use in a query string.

Returns the list of available predicates for the given resource, which may be functions or operators.

Removes the group or component with the given id

Remove the group with the given id

Remove the predicate with the given id

Same as to_filter/1

Returns a filter expression that can be provided to Ash.Query.filter/2

Update the predicate with the given id

Updates the filter with the provided input and validates it.

Link to this section Functions

Link to this function

add_group(form, opts \\ [])

View Source

Adde a group to the filter.

Options:

  • :to - The nested group id to add the group to.

  • :operator - The operator that the group should have internally. The default value is :and.

  • :return_id? - If set to true, the function returns {form, predicate_id} The default value is false.

Link to this function

add_predicate(form, field, operator_or_function, value, opts \\ [])

View Source

Add a predicate to the filter.

Options:

  • :to - The group id to add the predicate to. If not set, will be added to the top level group.

  • :return_id? - If set to true, the function returns {form, predicate_id} The default value is false.

  • :path - The relationship path to apply the predicate to

Link to this function

errors(form, opts \\ [])

View Source

Returns a flat list of all errors on all predicates in the filter.

Returns the list of available fields, which may be attributes, calculations, or aggregates.

Same as filter/2 but raises on errors.

Converts the form into a filter, and filters the provided query or resource with that filter.

Link to this function

new(resource, opts \\ [])

View Source

Returns the minimal set of params (at the moment just strips ids) for use in a query string.

Returns the list of available predicates for the given resource, which may be functions or operators.

Link to this function

remove_component(form, group_or_component_id)

View Source

Removes the group or component with the given id

Link to this function

remove_group(form, group_id)

View Source

Remove the group with the given id

Link to this function

remove_predicate(form, id)

View Source

Remove the predicate with the given id

Same as to_filter/1

Link to this function

to_filter_expression(form)

View Source

Returns a filter expression that can be provided to Ash.Query.filter/2

To add this to a query, remember to use ^, for example:

filter = AshPhoenix.FilterForm.to_filter_expression(form)

Ash.Query.filter(MyApp.Post, ^filter)

Alternatively, you can use the shorthand: filter/2 to apply the expression directly to a query.

Link to this function

update_predicate(form, id, func)

View Source

Update the predicate with the given id

Link to this function

validate(form, params \\ %{})

View Source

Updates the filter with the provided input and validates it.

At present, no validation actually occurs, but this will eventually be added.