angular-ui / ui-tinymce

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

How to getContent for a text area from tinyMCE when multiple editors on the same page? #279

Closed muqeet-khan closed 7 years ago

muqeet-khan commented 8 years ago

Hello, I have a scenario where I have 3 editors on the same page for 3 different model properties. I need to be able to access the content for these in raw from tinymce along with the HTML.

For now,

<textarea ui-tinymce="vm.tinymceOptions" ng-model="vm.submission.conclusion"></textarea>
<textarea ui-tinymce="vm.tinymceOptions" ng-model="vm.submission.example"></textarea>
 <textarea ui-tinymce="vm.tinymceOptions" ng-model="vm.submission.revision"></textarea>

is the HTML and JS as follows:

    function editSubmissionController($http,$routeParams,$location) {
        var vm = this;

        vm.tinymceOptions = {
            inline: false,
            plugins: 'advlist autolink link image lists charmap print preview',
            toolbar: "undo redo styleselect bold print",
            menubar: ""
        };
.........

All of the above works and I get the data in editor and also back in the JS when the submit button is clicked. I can also do the following:

vm.submission.conclusionSansHTML = tinymce.get('ui-tinymce-1').getContent({ format: 'text' });

however, the ID changes when the page is refreshed after submission and the above line starts failing. I have read I can not insert by own id's to these textareas so I was hoping some one had a solution to this issue. Thanks!

deeg commented 8 years ago

Do you only need the raw text format, or do you ned the regular HTML format from the model binding as well?

I believe you could set raw:true on the options which would make the model binding the raw text value instead.

If you need both, you could probably surf the dom and extract the ID out of it, but I know that is not pretty. Let me think on it and see if I can come up with anything else more elegant.

deeg commented 7 years ago

Closing this due to inactivity. Please feel free to open another issue if you believe you have a valid bug.