user3966432
user3966432

Reputation: 388

tinyMCE change event is working but not hidden textarea's

I have initiated the tinyMCE for the list of textarea's (around 12) using the below code (generated from TypeScript code).

tinymce.init({
        selector: this.selector,
        setup: function (editor) {
            editor.on('change blur', function () {
                editor.save();
                tinymce.triggerSave();
                console.info('tinyMCE change event fired.');
            });
        },
        branding: this.branding,
        menubar: this.menubarFlag,
        browser_spellcheck: this.browser_spellcheck,
        fontsize_formats: this.fontsize_formats,
        block_formats: this.block_formats,
        toolbar1: this.toolbar1,
        height: this.height,
        plugins: this.plugins
    });

I tried both editor.save(); and tinymce.triggerSave(); on tinyMCE change event. But still hidden textarea change event is not firing though content is updated to textarea.

I need textarea's event to actually add an element to the form by adding name attribute.

    $(divObj).find('.segment-input').change(function () {
         $(divObj).find('input[type="hidden"]').attr('name', $(divObj).find('input[type="hidden"]').attr('name-nochange'));
         $(divObj).find('input[type="hidden"]').removeAttr('name-nochange');
    });

Upvotes: 1

Views: 4436

Answers (1)

Michael Fromin
Michael Fromin

Reputation: 13726

Per your comments above check out this fiddle:

http://fiddle.tinymce.com/Cogaab

The editor.on() function has access to the editor (e in the fiddle) upon which it was triggered. You can get (among other things) the target ID of the underlying text area. In the fiddle I provided I log that to the console for each of the editors on init, change, and blur.

Once you know the ID you can find that using JavaScript and do what you need to that native element.

There is a variety of useful data in that editor (e) object - its worth logging e and looking at what else is there as other data there may also be helpful for your scenario.

Upvotes: 1

Related Questions