Search code examples
sapui5rich-text-editorsap-web-ide

SAPUI5 - How do I implement RichTextEditor?


Not Sure if the Documenatation is out of Date, but the standard code for creating a new richtext editor returns

Cannot read property 'RichTextEditor' of undefined

It looks like this is because there is no sap.ui.richtexteditor in the list of included resources.

var oRichTextEditor1 = new sap.ui.richtexteditor.RichTextEditor("myRTE1", {
    width:"100%", 
    height:"300px",
    showGroupClipboard:true,
    showGroupStructure:true,
    showGroupFont:true,
    showGroupInsert:true,
    showGroupLink:true,
    showGroupUndo:true,
    tooltip:"My RTE Tooltip"
});

What are my other options for a RichText/WYSIWYG editor in SAPUI5 ?


Solution

  • You should use the sap.ui.define syntax to require the RichTextEditor control in your controller. As the control library is not included in the resources, it would not be readily available.

    sap.ui.define([
      "com/sap/app/controller/BaseController",
      .
      .
      .
      "sap/ui/richtexteditor/RichTextEditor"
    ], function (BaseController, ........, RichTextEditor) {
    
    onAfterRendering: function () {
    
            var oRichTextEditor1 = new RichTextEditor("myRTE1", {
                width:"100%", 
                height:"300px",
                showGroupClipboard:true,
                showGroupStructure:true,
                showGroupFont:true,
                showGroupInsert:true,
                showGroupLink:true,
                showGroupUndo:true,
                tooltip:"My RTE Tooltip"
            }); 
      } 
    });