Upgrading Froala from 2.9.2 to 3.1.1 throws exception: "Cannot use 'in' operator to search for 'defaultView' in undefined"

Viewed 179

When I execute below code lines it throws exception in the console on executing (new FroalaEditor).

Code:

$.fn.validateFroalaChange = function () {
  var $obj = $(this);

  new FroalaEditor($obj, {
    events: {
      'contentChanged': function () {
        console.log("changed!!");
      }
    }
  });
};

Error:

froala_editor.pkgd.min.js:7 Uncaught TypeError: Cannot use 'in' operator to search for 'defaultView' in undefined
    at new E.Bootstrap (froala_editor.pkgd.min.js:7)
    at new $e (froala_editor.pkgd.min.js:7)
1 Answers

I encountered this too trying to migrate an old code-base to v3 and it turns out the Element should be a regular HTML Element, not a jQuery wrapped one.

So to fix your code, you would need to do either:

$.fn.validateFroalaChange = function () {   
  new FroalaEditor(this, {
    events: {
      'contentChanged': function () {
        console.log("changed!!");
      }
    }
  });
};

or initialize it like this, if for some reason you need to keep it as a jQuery object:

new FroalaEditor($obj.get(0), options)
Related