You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Trix will *always* use an associated `<input type="hidden">` element when the
116
+
> `[input]` attribute is set. To migrate to `<input>`-free support, set
117
+
> `willCreateInput = false`, then render the `<trix-editor>` without the
118
+
> `[input]` attribute.
119
+
120
+
> [!WARNING]
121
+
> In the absence of an `<input type="hidden">` element, the `<trix-editor>`
122
+
> element's value will not be included in `<form>` element submissions unless it
123
+
> is rendered with a `[name]` attribute. Set the `[name]` attribute to the same
124
+
> value that the `<input type="hidden">` element would have.
125
+
101
126
## Invoking Internal Trix Actions
102
127
103
128
Internal actions are defined in `controllers/editor_controller.js` and consist of:
@@ -156,7 +181,18 @@ To populate a `<trix-editor>` with stored content, include that content in the a
156
181
</form>
157
182
```
158
183
159
-
Always use an associated input element to safely populate an editor. Trix won’t load any HTML content inside a `<trix-editor>…</trix-editor>` tag.
184
+
Use an associated input element to initially populate an editor. When an associated input element is absent, Trix will safely sanitize then load any HTML content inside a `<trix-editor>…</trix-editor>` tag.
> When a `<trix-editor>` element initially connects with both HTML content *and*
194
+
> an associated input element, Trix will *always* disregard the HTML content and
195
+
> load its initial content from the associated input element.
160
196
161
197
## Validating the Editor
162
198
@@ -300,6 +336,27 @@ To store attachments, listen for the `trix-attachment-add` event. Upload the att
300
336
301
337
If you don’t want to accept dropped or pasted files, call `preventDefault()` on the `trix-file-accept` event, which Trix dispatches just before the `trix-attachment-add` event.
302
338
339
+
## Previewing Attached Files
340
+
341
+
Trix automatically previews attached image files. To determine whether or not to preview an attached file, Trix compares the file's content type against the [Trix.Attachment.previewablePattern](./src/trix/models/attachment.js#L7). By default, Trix will preview the following content types:
342
+
343
+
* `image/gif`
344
+
* `image/png`
345
+
* `image/webp`
346
+
* `image/jpg`
347
+
* `image/jpeg`
348
+
349
+
To customize an attachment's preview, listen for the `trix-attachment-add` event. When handling the event, set the attachment's `previewable` attribute, then change its preview URL by calling `setPreviewURL`:
You can manipulate a Trix editor programmatically through the `Trix.Editor` interface, available on each `<trix-editor>` element through its `editor` property.
@@ -558,6 +615,36 @@ For example if you want to keep a custom tag, you can access do that with:
The `<trix-editor>` element emits several events which you can use to observe and respond to changes in editor state.
@@ -568,6 +655,10 @@ The `<trix-editor>` element emits several events which you can use to observe an
568
655
569
656
* `trix-change` fires whenever the editor’s contents have changed.
570
657
658
+
* `trix-before-render` fires before the editor’s new contents are rendered. You can override the function used to render the content through the `render` property on the event. The `render` function expects two positional arguments: the `<trix-editor>` element that will render and a [DocumentFragment](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment) instance that contains the new content. Read [HTML Rendering](#html-rendering) to learn more.
659
+
660
+
* `trix-before-paste` fires just before text is pasted into the editor. You can use this to modify the content being pasted or prevent the paste event from happening at all. The `paste` property on the event contains the pasted `string` or `html`, and the `range` of the inserted text.
661
+
571
662
* `trix-paste` fires whenever text is pasted into the editor. The `paste` property on the event contains the pasted `string` or `html`, and the `range` of the inserted text.
572
663
573
664
* `trix-selection-change` fires any time the selected range changes in the editor.
@@ -578,6 +669,8 @@ The `<trix-editor>` element emits several events which you can use to observe an
578
669
579
670
* `trix-attachment-add` fires after an attachment is added to the document. You can access the Trix attachment object through the `attachment` property on the event. If the `attachment` object has a `file` property, you should store this file remotely and set the attachment’s URL attribute. See the [attachment example](http://trix-editor.org/js/attachments.js) for detailed information.
580
671
672
+
* `trix-attachment-edit` fires after an attachment is edited in the document. You can access the Trix attachment object through the `attachment` property on the event.
673
+
581
674
* `trix-attachment-remove` fires when an attachment is removed from the document. You can access the Trix attachment object through the `attachment` property on the event. You may wish to use this event to clean up remotely stored files.
582
675
583
676
* `trix-action-invoke` fires when a Trix action is invoked. You can access the `<trix-editor>` element through the event's `target` property, the element responsible for invoking the action through the `invokingElement` property, and the action's name through the `actionName` property. The `trix-action-invoke` event will only fire for [custom](#invoking-external-custom-actions) actions and not for [built-in](#invoking-internal-trix-actions).
0 commit comments