You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SugarCRM集成TinyMCE后无法获取编辑后字段值的问题

SugarCRM TinyMCE字段无法获取新编辑值的解决方法

问题背景

已在SugarCRM 12.0中配置TinyMCE字段(internal_notes),record.php配置代码如下:

array (
    'readonly' => false,
    'name' => 'internal_notes',
    'studio' => 'visible',
    'rows' => 3,
    'span' => 12,
    'type' => 'htmleditable_tinymce',  
    'span' => 12,   
    'tinyConfig' => array(     
        'script_url' => 'XXX/custom/epicom/tinymce/tinymce.min.js',     
        'height' => '100%',     
        'width' => '100%',     
        'theme' => 'advanced',     
        'skin' => 'sugar7',     
        'plugins' => 'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking save table contextmenu directionality emoticons template paste textcolor',     
        'entity_encoding' => 'raw',     
        'forced_root_block' => false,     
        'theme_advanced_buttons1' => "code,separator,bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,forecolor,backcolor,separator,fontsizeselect",     
        'theme_advanced_toolbar_location' => "top",     
        'theme_advanced_toolbar_align' => "left",     
        'theme_advanced_statusbar_location' => "none",     
        'theme_advanced_resizing' => false,     
        'schema' => 'html5',     
        'template_external_list_url' => 'lists/template_list.js',     
        'external_link_list_url' => 'lists/link_list.js',     
        'external_image_list_url' => 'lists/image_list.js',     
        'media_external_list_url' => 'lists/media_list.js',     
        'theme_advanced_path' => false,     
        'theme_advanced_source_editor_width'=> 500,     
        'theme_advanced_source_editor_height'=> 400,     
        'inlinepopups_skin' => 'sugar7modal',
        'relative_urls' => false,     
        'remove_script_host' => false,   
    ),
),

在record.js中生成HTML模板到文本区域后,保存记录时只能拿到旧HTML数据,使用tinymce.activeEditor.getContent()或tinymce.get("myTextarea").getContent()时,activeEditor始终为null,无法获取新内容。

解决方法

1. 利用SugarCRM的Model直接获取字段值

SugarCRM的编辑页面基于Backbone Model,编辑器内容会自动同步到对应Model字段,直接从Model取值即可:

// 获取当前记录的Model实例
var currentModel = this.model;
// 获取internal_notes字段的最新内容
var latestContent = currentModel.get('internal_notes');

2. 手动同步编辑器内容(自动同步失效时)

如果自动同步异常,先手动触发TinyMCE将内容同步到对应textarea,再获取值。注意SugarCRM中textarea的ID格式为[模块名]_[字段名](例如Accounts模块的该字段ID为Accounts_internal_notes):

// 替换为你的实际模块名+字段名
var editorId = 'Accounts_internal_notes';
var editor = tinymce.get(editorId);

if (editor) {
    // 同步编辑器内容到textarea
    editor.save();
    // 从textarea获取值
    var content = document.getElementById(editorId).value;
    // 可选:更新Model确保保存时获取最新值
    this.model.set('internal_notes', content);
}

3. 检查TinyMCE配置的关键项

  • 确认script_url路径正确,TinyMCE核心文件能正常加载(可通过浏览器开发者工具的Network标签验证)
  • 避免使用自定义的textarea ID,SugarCRM会自动生成关联的textarea,需使用模块+字段名的格式获取实例
  • 若使用旧版TinyMCE,确保theme与插件版本兼容,建议优先使用Sugar官方适配的配置项

内容的提问来源于stack exchange,提问作者Neeraj Verma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 20:17:01