3

I am reusing a tinymce control in an application. Basically I open the tinymce toolbar on the click of a link / button. I use the toolbar to select for instance bold or undo some text and then close the tinymce. When I open the tinymce again for another link / button the toolbar selections I had made the first time still seem to be clicked. For instance:

Opening tinymce first time, I select bold:

enter image description here

I then simply close the tiny mce and later open it up for another field, when I open it up for another field the B setting is still enabled (button is pushed in as shown in the image above). Is there a way to programitically reset the toolbar selections upon opening the tinymce. I looked at their documentation and found nothing

JonH
  • 32,732
  • 12
  • 87
  • 145

3 Answers3

1

Check this fiddle. This will clear any formatting if previously exists and will also reset all formatting buttons in case you have an empty editor.

tinymce.activeEditor.execCommand('selectAll');
tinymce.activeEditor.execCommand('RemoveFormat');

These two lines do this, select all content and then remove format.Best part is it works even when you have empty tinymce editor.

EDIT To serve your purpose, when an editor is opened, just click on "Bold" button and then click on the "remove format" button we have included. This will reset the "Bold" button clicked.

tushar.dahiwale
  • 146
  • 2
  • 13
0

A way you can try is reloading the entire tinyMCE. Try using this code in order to remove it:

tinyMCE.execCommand('mceRemoveControl', true, 'editor_id');

And then init it again:

tinyMCE.init({
  /* TinyMCE options */
 });
}
Alfonso Jiménez
  • 1,235
  • 1
  • 13
  • 24
-2

Please see their page - Click here

removeformat : [
{selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
{selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
{selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
]

write this code in init method.

If you add this in your tinymce config file. This will reflect on every instance of tiny mce you initialize.

tushar.dahiwale
  • 146
  • 2
  • 13
  • This does not explain or point out what you are fixing, please clarify. – JonH May 02 '14 at 12:16
  • You saying in your question that you checked their documentation, but the piece of code I have written above, is right from the documentation page and that page URL is - http://www.tinymce.com/wiki.php/Configuration%3aformats. On this page, scroll to bottom, read up there, they have written that if you want to RESET / Clear the formats of tinymce toolbar, you may use the "removeformat: [bla bla bla]' part in the init method of the tinymce toolbar. Now, is that clear? Remove that down vote because answer tells it all. One has to write short answers. – tushar.dahiwale May 04 '14 at 01:44
  • that removes a "specific format" can you imagine how long this would be to explicitly state that. Please re-read the question. – JonH May 05 '14 at 15:43
  • @JonH can u give any fiddle or link? i want to see the live problem. b'coz i am unable to understand that my suggestion won't work for you. – tushar.dahiwale May 06 '14 at 07:01
  • only thing I could do is a gotomeeting, no fiddles for this as there is just too much there. – JonH May 06 '14 at 17:00
  • i have reassured my answer and re-read your question. if you are calling `.init()` method, each time you a tinymce toolbar is opened, then you can surely use that `removeformat` parameter in the `.init()` method. wish you all the best. – tushar.dahiwale May 07 '14 at 06:04
  • The code given above address 'all' the formats, so there won't be anything more required to address any other format by specifying them explicitly. – tushar.dahiwale Oct 20 '22 at 13:53