Question T8234
Visible to All Users

I have to use Froala instead of Ckeditor 4, how to replace ckeditor 4 question with Froala?

created 4 years ago

Hello

Due to various reasons, I am not allowed to use ckeditor 4 for my project.

I have to use Froala for both questions and property editor.

How can it achieve it?

Thanks

Answers approved by surveyjs Support

created 4 years ago

Hello,

You need to learn the Froala editor API and rewrite corresponding code of your custom widgets.

Thanks, Serge
SurveyJS Team

    Comments (3)

      Thanks for the quick reply.

      other than include the Froala codes in my project, I should also change the codes below. is it correct?

      Code
      const adjustedCkeditorModalEditor = { afterRender: function (modalEditor, htmlElement) { const editor = adjustedCkeditor.replace( htmlElement, { removeButtons: that.removeButtons }); editor.on("change", function () { modalEditor.editingValue = editor.getData(); }); that.imageUploadAndPasteConfig(editor); editor.setData(modalEditor.editingValue); }, destroy: function (modalEditor, htmlElement) { const instance = adjustedCkeditor.instances[htmlElement.id]; if (instance) { instance.removeAllListeners(); adjustedCkeditor.remove(instance); } }, };
      Code
      const widget = { name: 'editor', title: 'Editor', iconName: 'icon-editor', widgetIsLoaded: function () { return typeof adjustedCkeditor != 'undefined'; }, isFit: function (question) { return question.getType() === 'editor'; }, htmlTemplate: "<textarea rows='10' cols='80' style: {width:'100%'}></textarea>", activatedByChanged: function (activatedBy) { Survey.JsonObject.metaData.addClass("editor", [], null, "empty"); Survey.JsonObject.metaData.addProperty("editor", { name: "height", default: 300, category: "general", }); }, afterRender: function (question, el) { const name = question.name; adjustedCkeditor.editorConfig = function (config) { config.language = "es"; config.height = question.height; config.toolbarCanCollapse = true; }; el.name = name; if (adjustedCkeditor.instances[name]) { adjustedCkeditor.instances[name].removeAllListeners(); adjustedCkeditor.remove(adjustedCkeditor.instances[name]); } let editor = adjustedCkeditor.replace( el, { removeButtons: that.removeButtons }, ); adjustedCkeditor.instances[name].config.readOnly = question.isReadOnly; that.imageUploadAndPasteConfig(editor); var isValueChanging = false; var updateValueHandler = function () { if (isValueChanging || typeof question.value === "undefined") return; editor.setData(question.value); }; editor.on("change", function () { isValueChanging = true; question.value = editor.getData(); isValueChanging = false; }); question.valueChangedCallback = updateValueHandler; question.readOnlyChangedCallback = function () { if (question.isReadOnly) { editor.setReadOnly(true); } else { editor.setReadOnly(false); } }; updateValueHandler(); }, willUnmount: function (question, el) { question.readOnlyChangedCallback = null; if (adjustedCkeditor.instances[question.name]) { adjustedCkeditor.instances[question.name].destroy(); } }, pdfRender: function (survey, options) { if (options.question.getType() === "editor") { const loc = new Survey.LocalizableString(survey, true); loc.text = options.question.value || options.question.defaultValue; options.question["locHtml"] = loc; if ( options.question.renderAs === "standard" || options.question.renderAs === "image" ) { options.question["renderAs"] = options.question.renderAs; } else options.question["renderAs"] = "auto"; const flatHtml = options.repository.create( survey, options.question, options.controller, "html" ); return new Promise(function (resolve) { flatHtml.generateFlats(options.point).then(function (htmlBricks) { options.bricks = htmlBricks; resolve('done'); }); }); } }, };

        Hello,

        Yes, you need to re-write all code related to CKEDITOR

        Thanks, Serge
        SurveyJS Team

          Great!

          Thanks!