Filter Asset Picker

I feel like I am missing something simple.
I want to be able to filter an asset picker form control so that it only returns options that are assets linked to the current record.
I have a Preside Object called animal that holds data on animals. There is a property on the object named images that is a many-to-many relationship to assets.
I also have a main_image property in the object where I want to allow the admin user the ability to select an image from the images uploaded for that animal.
I thought I could do this in my form definition but it doesn’t seem to have any effect
<field binding="animal.main_image" sortorder="20" control="assetPicker" filterby="id" filterbyfield="animal" />
I’m using filterby and filterbyfield on a load of other form fields with object pickers (not related to assets) and just assumed the same approach would work with the asset picker.

I would look at the blog extension. I had to do something similar to the blog categories. Under /preside-ext/blog/services/BlogService.cfc, it has some sample code you could use to create the pre and post-routing logic. I am still new to preside, so I apologize in advance if this is not a hundred percent.

1 Like

This may be a missing feature @iain . I’d recommend jumping into the source code of the form control in the core:

Docs: Preside Documentation :: Preside form controls

This one at: /preside/system/handlers/formcontrols/AssetPicker.cfc

Thanks Dom.
Yeah, I took a look at that the other day. The docs suggest that the asset picker is a ‘customized extension of the object picker’ so I had assumed that like other controls that use the object picker that I would be able to pass in any object picker attributes such as filterby and they would just work. Having looked at the code that doesn’t seem to be the case.
I have a requirement in a current project to be able to filter assets in the picker so I’ll look at adding that option to the form control and hopefully submit a pull request.

2 Likes