How to make an element in a TinyMCE editor treated as a non-editable single item?

前端 未结 4 1016
北恋
北恋 2021-02-04 11:14

Within our CMS, our users can edit error messages for forms using TinyMCE. The problem is, some of these messages may require dynamic data, e.g. \"Your chosen name \'X\' i

4条回答
  •  清酒与你
    2021-02-04 12:07

    After trying about 100 different work arounds, we finally found a solution which works (for our needs anyway).

    We're inserting a disabled button with all the styles removed. For example,

    
    

    And then adding some code to onGetContent() to convert the input to plain text.

    This solution, although not very elegant,

    1. Makes the token behave as a single character/item.
    2. Makes it read only.
    3. Is dynamic in the context of the editor so we can display our token text.

    Edit: This is what we ended up with.

    enter image description here

提交回复
热议问题