AshPhoenix.FilterForm (ash_phoenix v0.6.0-rc.3) View Source

Create a new filter form.

Options:

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

  • :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.

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

Same as filter/2 but raises on errors.

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

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

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.

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.
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.

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

Same as filter/2 but raises on errors.

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

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(form)

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

Alternatively, you can use the shorthand: filter/2.

Same as to_filter/1

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.