@trix' }) element.editor.insertAttachment(attachment) I used this snippe" /> @trix' }) element.editor.insertAttachment(attachment) I used this snippe" /> @trix' }) element.editor.insertAttachment(attachment) I used this snippe"/>

"new Trix is not defined" when using Basecamp / Trix Editor

592 Views Asked by At
var attachment = new Trix.Attachment({ content: '<span class="mention">@trix</span>' })
element.editor.insertAttachment(attachment)

I used this snippet but it throwed error: Trix is not defined?? How can i handle it? Thank you!

1

There are 1 best solutions below

0
Daniel Gonzalez On BEST ANSWER

This is probably because the script

var attachment = new Trix.Attachment({ content: '<span class="mention">@trix</span>' })
element.editor.insertAttachment(attachment)

is executing before the trix.js or the npm package(however you are implementing it). For now I haven't found a listener when Trix is ready so a quick solution is to use a CDN instead of those.

<script src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.3.0/trix.js"></script>

These should work if you don't have a problem with the use of CDN