user1728278
user1728278

Reputation: 625

TinyMCE: validate elements on each keystroke

I'm using TinyMCE as a base for a WYSIWYG editor, and I'd like to only allow a subset of HTML elements to be entered in it, whatever the mean.

There are three different means of entering HTML elements into the editor: buttons (such as a bold button), shortcuts (CTRL+B for bold) and copy-pasting.

I'm using a custom template, so I only have a limited number of buttons that allow for a certain number of elements.

But using shortcuts or copy/pasting, the user can add whatever he wants to the editor.

The valid_elements configuration option allows to filter out elements (it works as a whitelist), but it's only triggered on cleanup, which (AFAIK) is only run when the form is submitted.

This is great, but I don't want things to be added to the editor in the first place if they're not valid elements.

How could I achieve that behavior?

Upvotes: 1

Views: 217

Answers (1)

Thariama
Thariama

Reputation: 50832

This is great, but I don't want things to be added to the editor in the first place if they're not valid elements.

This is not that easy because you will need to check each way of which code can get into the editor and check before the insertion if the html code is valid. It might be easier to call the cleanup yourself on those actions:ed.execCommand('mceCleanup');

Otherwise you will have to check for

  • the insertion using the code plugin
  • copy/paste using the paste_preprocess setting
  • the insertion using the code plugin
  • and the most annoying: pasting using the right click browser menu (this is a pain in the ass to handle)

Upvotes: 1

Related Questions