I would like to know if it’s possible to have a field (Multi select or dropdown) with dynamic data loaded from an external API.
Basically I have an API with lots of items IDs, and i would like that when I’m adding an entry in Cockpit, to be able to associate that entry with a specific ID i have in my external API.
Example: I have a collection named “Images” and fields - “ID” and “Image” and when I’m adding a new entry, i select an ID (or name) in the Select list and then I upload an image in the image field. That way, the image i uploaded, is associated with the desired ID in the first field.
I hope it is clear enough and I wonder if it’s possible. Thank you.
Hey @dragosdydy, I think so, but not out of the box, you need to build the field in a new addon, it’s not a complex task, you just need to pre-populate the field with the dynamic data. On your field configuration instead of having the field options (id, value) you have your api endpoint. Check the modules/Cockpit/assets/components/field-select.tag to see how the dropdown field is implemented, you can duplicate it (inside your addon) and perform the required changes.
Thank you @pauloamgomes. The issue is that I can’t find any documentation about creating an addon.
Another question, if you have any idea. Would it be possible to import entries in a collection using an API? At the moment, I can see there’s an option to import from CSV files.
Hey @dragosdydy, yeah, the documentation doesn’t provide that, we can’t have everything! its already hard work from the cockpit author…
my suggestion is to look some of the existing addons to understand how they work (I learned that way). Yes, in theory, you can import from any source if you build what is required, you can do a simple addon with a controller and a view, you can have in the view only the minimal interface to trigger the import. The import will only need to leverage the API calls, handle the results and save them as new collection entries.