Hi Grant,
We’ve now updated to 7.12.1 and in the process I had a chance to look into this a little more thoroughly! I was able to get it to work, but found some rather weird things in the process. Apologies if this gets a little wordy or hard to follow.
Previously, all of our custom/defined attachment forms were in the format TableAttachmentBRI (LoanAttachmentBRI, TaxonAttachmentBRI etc.) - these don’t work and my original solution of creating a copy of them called ObjectAttachment for each table made some cool bugs.
When I created an CollectionObjectAttachment form called ObjectAttachment and a TaxonAttachment form called ObjectAttachment, the CollectionObject didn’t work but Taxon did. But if I used the ‘Edit form defintion’ button, the CollectionObjectAttachment form would load despite not being used, but the TaxonAttachment form would 404 trying to open the path /CollectionObjectAttachment/originalObjectAttachment/, even though it displayed the correct fields!
After a bit of digging I think I have some idea of what was happening:
useViewDefintion only works to render the attachment pluging when the name is ObjectAttachment exactly - the PR that fixed the issue (7811) makes the renderer use the flag isAttachmentPlugin?, but the value for it is still hardcoded to ObjectAttachment itself, so the TableAttachmentBRI fields would never render the attachment plugin, even after the PR.
The second part was that the AttachmentViewer in Viewer.tsx queries to get an exact attachment table name, rather than being passed the attachment form from (and also doesn’t have anything for preferring definitions with a database viewsetid). This means that it was searching for CollectionObjectAttachment and TaxonAttachment directly - so it was getting the global view backstop for CollectionObjectAttachment (which is why it rendered the default form), but couldn’t find one for the Taxon table (as there isn’t one) - falling back to ObjectAttachment via originalObjectAttachment, which 404s because the name change breaks the URL.
Obviously creating multiple forms called ObjectAttachment wasn’t the way to go about it, but it did also mean that the taxon level was picking up the CollectionObjectAttachment ObjectAttachment because it wins the hierarchy of Discipline → Collection.
The solution in the end is that you can have customised attachment forms, it just took me a while to figure out the process was to go through each AttachmentBRI, create a copy of it called just TableAttachment, and then changing the form itself to use ObjectAttachment when calling the subview - e.g:
Copying TaxonAttachmentBRI into just TaxonAttachment
and then changing the Taxon form from:
cell type=“subview” id=“attachment” viewname=“TaxonAttachmentBRI” name=“taxonAttachments” colspan=“2” initialize=“btn=true;icon=TaxonAttachment”
to
cell type=“subview” id=“attachment” viewname=“ObjectAttachment” name=“taxonAttachments” colspan=“2” initialize=“btn=true;icon=TaxonAttachment”
This full method still doesn’t play super nicely with Specify 6, which doesn’t render any of the fields this way, but at this point thats fine (we’ve almost entirely moved off Specify 6 now), and at the very least this method allows for attachments to be added in both. Specify 6 is now missing all of the fields except File Name and Title but before there was no way to get both Specify 6 and 7 to have the ability to add attachments at all with custom forms so I’m counting it as a win.
I also managed to find a bug in our configuration where because one of our ExchangeInAttachment forms was incorrectly defined as a GiftAttachment datamodel, the Specify 7 ‘Create’ form button on GiftAttachment would 404, which was kinda fun to debug - it was definitely an issue on our end, but it took me a while to find because it was the definition in our second collection that was causing the error when trying to look up the existing forms as templates.
Depending on whether or not you think the naming of the attachment forms being restricted to TableAttachment is a bug or a feature I don’t think there’s much that needs to be done for this, but I figured I’d write it out anyway just in case anyone else is having issues with Attachment forms link to the wrong tables because of weird ObjectAttachment naming stuff.
Let me know if anything here doesn’t make sense.
Thanks for your help with this, and with Specify 7.12.1! We did the update today so I’m keen to get into using the new features (and hopefully not find too many bugs
)