Difficulty injecting custom button into Image/Attachment fields via afterAppRun

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1838

    #1

    Difficulty injecting custom button into Image/Attachment fields via afterAppRun

    I am developing a custom extension (let's call it "ImageEditor") for EspoCRM and I'm struggling to inject a custom "Edit" button into the attachment preview blocks.

    My setup:
    • EspoCRM version: 9.x
    • Goal: Add a button to .attachment-preview to open a custom modal for image editing.

    What I've done so far:
    1. Registered the script via afterAppRunList in metadata/app/client.json.
    2. The script successfully logs to the console, so it is being loaded.
    3. I am using an setInterval loop to scan for .attachment-block-preview or a[data-action="showImagePreview"].

    The problem: Even though the script runs and the HTML is visible in the Inspector, jQuery selectors like $('.attachment-preview') or $('a[data-id]') often return length: 0 in the script context, or the injection via .after() / .append() simply doesn't manifest in the DOM.

    Additionally, I've encountered CSP (Content Security Policy) blocks when trying to load the script as a standard scriptList entry, so I moved it to afterAppRunList.

    Questions:
    1. Is there a recommended "Espo-way" to extend the Attachment or Image field views specifically to add custom actions/buttons without overwriting the entire .tpl file?
    2. How can I ensure my script has access to the DOM after the AJAX-driven fields have finished rendering?
    3. Are there specific CSP considerations for scripts in client/custom/modules/... that might prevent DOM manipulation even if the script itself executes?

    Any guidance on the correct "Entry Point" for DOM manipulation in the record detail view would be greatly appreciated!
  • rabii
    Active Community Member
    • Jun 2016
    • 1376

    #2
    i am not aware of afterAppRunList is this part of the metadata ?

    Best way is monkey patching as you are changing one modal used in different places of the system and there is no way to extend that modal.
    Rabii
    EspoCRM & Web Dev

    🔗 See what I’ve built for EspoCRM

    Comment

    Working...