Now.js Framework Documentation
RichTextElementFactory
RichTextElementFactory
Loaded on demand — part of the feature bundle
now.richtext.min.js, not ofnow.core.min.js:data-element="richtext"markup loads it; code that usesRichTextElementFactorydirectly callsawait Now.require('RichTextElementFactory')first — see Feature bundles
Connects RichTextEditor to ElementManager: <textarea name="detail" data-element="richtext" data-attr="value:detail"></textarea>
| Attribute | Meaning |
|---|---|
data-rte-profile="basic\|full\|minimal\|comment" |
The editor's tool set (default basic) |
data-rte-height="400" / data-rte-min-height="200" / data-rte-max-height |
Height in px |
data-rte-placeholder="..." |
Placeholder text |
data-rte-sticky="true" |
Sticky toolbar |
data-rte-allow-style="true" |
HTML pasted from outside keeps <style> |
data-rte-allow-script="true" |
HTML pasted from outside keeps <script> |
data-rte-allow-iframe="false" |
HTML pasted from outside loses <iframe> |
data-rte-allow-interactive-tags="button\|select" |
HTML pasted from outside keeps these form controls (true for all) |
The editor posts what the author wrote
The editor drops nothing by itself: the server decides what is kept. Content that is loaded (from the database, or typed in source
view) comes back from getContent() and on form submit with every part: <style>, <script>, <link>, <noscript>, forms and
buttons, onclick, javascript: links, comments, and iframes with all their attributes.
While it is edited, nothing in the content runs or loads in the admin page:
- An element that would run, load or submit is shown as a placeholder where it stands (a small chip such as
script · pagead2.googlesyndication.com,style,form,button · Play; an iframe is a box of its real size). It can be clicked,
moved, cut and pasted, and deleted like an image; its code is edited in source view. - An attribute that would run (
on*, ajavascript:URL,autofocus) is held back; the element itself stays editable. - CSS from the content's own
<style>shows inside the editing area only (rules inside@mediaincluded), never on the admin page. - The editor's footer says what is held, e.g.
Embedded: 1 style • 2 scripts.
HTML pasted from outside (the clipboard from another site or Word, an AI answer, embed code typed into the iframe dialog) is still
cleaned: scripts, handlers and script URLs are removed — paste code in source view instead. Cut or copy and paste inside the editors
of one page keeps every part.
Source view lays the markup out for reading without changing it (no white space added or lost between words; <pre>, <script>,
<style> and comments exactly as they are). One limit: <!DOCTYPE>, <html>, <head> and <body> survive only when saving straight
from source view; switching back to the normal view drops those wrappers (what is inside them stays).
On the server (Kotchasan), pick the level by who writes:
| Use | Keeps |
|---|---|
$request->post('detail')->detail() |
Everything as written, CSS and JS included — authorised authors (articles, pages, mail templates) |
$request->post('detail')->detail(false) |
Everything except what can run JavaScript; CSS, forms and iframes stay |
$request->post('comment')->cleanHtml() |
Formatting only — content from the public |
Before this was fixed (2026-11-11) the editor removed
<style>,<script>, forms and handlers by itself when content was loaded in
the normal view, so opening an article and saving it lost ad code or CSS; and it parsed content in the live document, which let an
<img onerror>in the content run on load and on paste.Generated from source on 2026-08-21. Descriptions come from JSDoc in the file.
Re-rundocs_scaffoldwhen the code changes; hand edits are lost on regeneration
Source
- File:
Now/js/RichTextElementFactory.js - Form: ES class
Public methods (3)
static cleanup(instance)
Destroy the editor attached to this element and release the reference. Safe to call when no editor was created, and errors thrown by the editor's own destroy are swallowed so teardown of the surrounding form still finishes.
static extractCustomConfig(element, def, dataset)
Read the editor options a single element declares through its data-rte-* attributes. Anything not declared falls back to the value in def, and placeholder also falls back to the element's own placeholder attribute.
static setupElement(instance)
Attach a RichTextEditor to the element and keep it in sync with the form. The editor bundle is loaded separately, so this retries every 100 ms until window.RichTextEditor exists rather than failing when it is not ready yet.
Data attributes used
data-read-only · data-rte-allow-iframe · data-rte-allow-interactive-tags · data-rte-allow-script · data-rte-allow-style · data-rte-fallback-bound · data-rte-fallback-loaded · data-rte-height · data-rte-max-height · data-rte-media-fallback · data-rte-min-height · data-rte-placeholder · data-rte-profile · data-rte-sticky
Depends on
ElementFactory · ElementManager