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
Copy file name to clipboardExpand all lines: README.md
+17-9Lines changed: 17 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,30 +55,38 @@ Like an HTML `<textarea>`, `<trix-editor>` accepts `autofocus` and `placeholder`
55
55
56
56
## Integrating With Forms
57
57
58
-
To submit the contents of a `<trix-editor>` with a form, first define a hidden input field in the form and assign it an `id`. Then reference that `id` in the editor’s `input` attribute.
58
+
To label a `<trix-editor>` element, render the element with an `[id]` attribute, then render a `<label>` element with a `[for]` attribute that corresponds to the `[id]`:
59
+
60
+
```html
61
+
<labelfor="editor">Editor</label>
62
+
<trix-editorid="editor"></trix-editor>
63
+
```
64
+
65
+
To submit the contents of a `<trix-editor>` with a `<form>`, render the element with a `[name]` attribute and its initial value as its inner HTML.
59
66
60
67
```html
61
68
<form…>
62
-
<inputid="x"type="hidden"name="content">
63
-
<trix-editorinput="x"></trix-editor>
69
+
<trix-editorname="content"></trix-editor>
64
70
</form>
65
71
```
66
72
67
-
Trix will automatically update the value of the hidden input field with each change to the editor.
73
+
To associate the element with a `<form>` that isn't an ancestor, render the element with a `[form]` attribute that references the `<form>` element by its `[id]`:
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.
81
-
82
90
## Styling Formatted Content
83
91
84
92
To ensure what you see when you edit is what you see when you save, use a CSS class name to scope styles for Trix formatted content. Apply this class name to your `<trix-editor>` element, and to a containing element when you render stored Trix content for display in your application.
0 commit comments