View Source AshPhoenix.FilterForm (ash_phoenix v1.2.11)
Create a new filter form.
Options:
:params
(term/0
) - Initial parameters to create the form with The default value is%{}
.:as
(String.t/0
) - Set the parameter name for the form. The default value is"filter"
.:transform_errors
(term/0
) - Allows for manual manipulation and transformation of errors.
If possible, try to implementAshPhoenix.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?
(boolean/0
) - 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 isfalse
.
Link to this section Summary
Functions
Adde a group to the filter.
Add a predicate 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
Returns a filter map that can be provided to Ash.Filter.parse
Update the predicate with the given id
Updates the filter with the provided input and validates it.
Link to this section Functions
Adde a group to the filter.
Options:
:to
(String.t/0
) - 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?
(boolean/0
) - If set totrue
, the function returns{form, predicate_id}
The default value isfalse
.
add_predicate(form, field, operator_or_function, value, opts \\ [])
View SourceAdd a predicate to the filter.
Options:
:to
(String.t/0
) - The group id to add the predicate to. If not set, will be added to the top level group.:return_id?
(boolean/0
) - If set totrue
, the function returns{form, predicate_id}
The default value isfalse
.:path
- The relationship path to apply the predicate to
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
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.
Returns a filter map that can be provided to Ash.Filter.parse
This allows for things like saving a stored filter. Does not currently support parameterizing calculations or functions.
Update the predicate with the given id
Updates the filter with the provided input and validates it.
At present, no validation actually occurs, but this will eventually be added.