Smart field filtering

I created a smart field on collection A (= foreign key to collection B).
When I create a record on collection A, for this smart field, I have a drop down with all possible values from the linked collection B.
I need to filter this dropdown, but I can’t find a way to do it.
I see the web front dropdown queries a route /forest/{collection B}
Since it’s not /routes/{collection B} I’m not sure I can override it with .js files in routes folder.

Moreover, I want the filter to apply to the dropdown of collection A, not on the normal list of collection B.

How can this be done? I basically want a smart field dropdown to show filtered list of records from the linked collection

Hi @francois_Ruty,

Did you try to configure a dropdown widget on your smart field?
You should be able to apply filtering conditions to fit your needs.

See more details about it here:

Let me know if it help.

Hello, apologies, I was not clear enough:

  • the field on collection A is not a smart field but a smart relationship
  • the field in collection B on which I want to filter is a smart field, not a regular field

I indeed found the filtering options for the edit widget, but the collection B field I want to filter on is a smart field, and it seems dropdown filtering does not allow me to choose a smart field in collection B.

How could I work around that?

Hi @francois_Ruty,

Unfortunately, ForestAdmin does not support filtering on smart fields. That is because filters are directly applied in SQL queries, which cannot natively be understand how you defined your smart fields.

However I can log your need for filterable smart field for future prioritization.

hello, I know it’s not supported by FA but what would you recommend as a workaround?

I could override the GET route on collection B so that it filters how I want to, when the call is being made for a dropdown
When calling the API to fetch dropdown values, isn’t FA sending elements of context that indicates it’s for a dropdown? If yes I can just override the GET route and do the filtering myself, in the event the endpoint is called by a dropdown

1 Like

Hey @francois_Ruty,

If the filter is the same you can override the route /forest/{collection B} and do something like that:

router.get('/forest/collection B', permissionMiddleware.list(), (request, response, next) => {
      if (request.query && request.query.context && request.query.context.recordId) {
        // NOTICE: This is when you are in a dropdown
        // FIXME: DO your filtering here

1 Like

thanks for the suggestion

1 Like

Hi @francois_Ruty,

If these are recurring filters you’ll use a lot, another alternative might be to compute the field in a Smart Segment and apply your filtering on it. Only record :ids that pass your filter will be returned in the Segment.

Let us know what works better for you :slight_smile: