We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33968
    • 863 Posts
    I've implemented TinyMCE on an ExtJS Window that works fine on first load, but after hiding, calling setValues() with new data, then showing the Window again the rich-text field is not updated with the new data. It shows the same data as when it was first loaded.

    Code is roughly as follows (simplified for clarity):
    MyCmp.window.RichText = function(config) {
        config = config || {};
        
        Ext.applyIf(config,{
            layout: 'form'
            ,fields: [{
                xtype: 'textarea'
                ,name: 'rte_field'
                ,id: 'mycmp-rte-field'
                ,fieldLabel: 'Rich Text Field'
            }]
        });
        MyCmp.window.RichText.superclass.constructor.call(this,config);
        this.on('activate',function() {
            // load Rich Text Editor
            if (typeof Tiny != 'undefined') { 
                MODx.loadRTE('mycmp-rte-field');
            }
        },this);
    };
    Ext.extend(MyCmp.window.RichText,MODx.Window);
    Ext.reg('mycmp-window-richtext',MyCmp.window.RichText);
    


    The window record is updating with the new data, so it appears I need to reload/refresh TinyMCE somehow. Any ideas? [ed. note: okyanet last edited this post 11 years, 9 months ago.]
      • 33968
      • 863 Posts
      Never mind, managed to solve it. For anyone else, you need to use TinyMCE's setContent function to update the editor when the textarea value changes:
      MyCmp.window.RichText = function(config) {
          config = config || {};
           
          Ext.applyIf(config,{
              layout: 'form'
              ,fields: [{
                  xtype: 'textarea'
                  ,name: 'rte_field'
                  ,id: 'mycmp-rte-field'
                  ,fieldLabel: 'Rich Text Field'
              }]
          });
          MyCmp.window.RichText.superclass.constructor.call(this,config);
          this.on('activate',function() {
              // load Rich Text Editor
              if (typeof Tiny != 'undefined' && !this.RTEloaded) { 
                  MODx.loadRTE('mycmp-rte-field');
                  this.RTEloaded = true;
              }
          },this);
          this.on('show',function() {
                  if (this.RTEloaded) {
                      tinyMCE.get('mycmp-rte-field').setContent('new content...');
                  }                 
          },this);
      };
      Ext.extend(MyCmp.window.RichText,MODx.Window);
      Ext.reg('mycmp-window-richtext',MyCmp.window.RichText);