Skip to content

Commit 21381eb

Browse files
committed
Document code-input_load event
1 parent 57d9006 commit 21381eb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

docs/interface/js/_index.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ title = '`code-input` vs the `textarea` in JavaScript'
66

77
> Contributors: 2025 Oliver Geer
88
9-
Once registered, `code-input` elements support the JavaScript properties and events used with a `textarea` element, because they are built around them. Try swapping out your `textarea` element in your JavaScript application for a `code-input`! If it doesn't work, [submit a bug report](https://github.com/WebCoder49/code-input/issues).
9+
[Once registered](#code-input_load), `code-input` elements support the JavaScript properties and events used with a `textarea` element, because they are built around them. Try swapping out your `textarea` element in your JavaScript application for a `code-input`! If it doesn't work, [submit a bug report](https://github.com/WebCoder49/code-input/issues).
1010

1111
If you want to replace a `textarea` with a `code-input` in an application that doesn't need JavaScript, [look here](../forms). We support HTML5 forms, and progressive enhancement so JavaScript isn't needed!
12+
13+
## The `code-input_load` event {code-input_load}
14+
15+
Each `code-input` element fires a `code-input_load` event when it, its template and its plugins have been fully registered. You should carry out initialisation code for `code-input` elements in a handler for this event:
16+
```javascript
17+
// TODO: Get code-input element as codeInputElement
18+
codeInputElement.addEventListener("code-input_load", () => {
19+
// TODO: Initialisation code
20+
// TODO: Add event handlers to the element here.
21+
});
22+
```
23+
24+
For backwards compatibility, you should also implement the subset of the functionality that doesn't require `code-input.js` on the `<textarea data-code-input-fallback>` element before load, if you have one. For backwards compatibility and technical reasons, event handlers registered in HTML attributes like `onchange` of the textarea will be passed to the code-input element when it is registered, but event listeners registered like that above will not.

0 commit comments

Comments
 (0)