angular-ui / ui-tinymce

AngularUI wrapper for TinyMCE
MIT License
488 stars 371 forks source link

how to set dynamically tinymce in readonly mode ? #344

Closed ngavard closed 6 years ago

ngavard commented 6 years ago

Hi ui-tinymce team,

I tried to use myCtrl.tinyMceOptions = { inline : true, plugins : " code fullscreen paste lists advlist table emoticons textcolor hr", menubar: false, toolbar : 'bold [...] ', readonly : myCtrl.readonly //set readonly } ;

and

<div ui-tinymce="myCtrl.tinyMceOptions" ng-model="ctrl.content" ></div>

But when myCtrl.readonly is updated, tinymce is not refreshed.

I tried

$scope.$watch("myCtrl.readonly", function(readonly, oldVal){ $scope.$broadcast('$tinymce:refresh'); }); I see Tinymce refreshed but not in readonly. I tried the ng-readonly directive in the div without success.

I saw that there is an issue with ng-disabled currently open. I wonder if there is a chance that ng-readonly could be handled the same way as ng-disabled ?

ghost commented 6 years ago

@ngavard I am now doing something like this:

$scope.tinymceOptions = {

    setup: function(editor) {
        // only focus event worked in my app :-(
        editor.on('focus', function(event) {
            var editor = event.target;
            if (editor.readonly === true) {
                event.target.setMode('readonly');
            }
        })
    }
}

Not sure if there is a better way.

ngavard commented 6 years ago

Thanks! @varmanishant

setMode('readonly') works for me.