trix icon indicating copy to clipboard operation
trix copied to clipboard

Insert image to trix-editor through javascript

Open adiubaidah opened this issue 1 year ago • 3 comments

Does anyone know how to insert attachment in trix editor with javascript ?,

  1. I have the image through the url, and that url is working properly
  2. and when i use const attachment = new Trix.Attachment({content : url}) and insertAttachment, it only display the url not the image
  • Trix version: 2.04
  • Browser name and version: Chrome Version 112.0.5615.49 (Official Build) (64-bit)
  • Operating system: Windows

adiubaidah avatar Apr 08 '23 04:04 adiubaidah

Hey, have you found a solution to this?

stanj98 avatar Dec 24 '23 11:12 stanj98

Have you tried?

new Trix.Attachment({content : url, contentType:"image"})

andrii-baran-nfgp avatar Feb 15 '24 14:02 andrii-baran-nfgp

function addImageUrl(url, caption) {
    const attachment = new Trix.Attachment({ filename: caption, url: url, contentType: "image/png" })
    element.editor.insertAttachment(attachment)
}

this worked for me.

sejutaimpian avatar May 04 '24 13:05 sejutaimpian