2011-10-12 107 views
1

所有textareas都內聯,StackedInlineDjango TinyMCE問題

所有textareas在此模型change_view中正常工作。但是,當我添加一個新行時,最後一行在textarea中不可編輯。

如果我刪除了tunyMCE Init中的「textareas」模式,它會刪除wsgi編輯器,但是當添加新文件時textareas會工作。所以我想它的tinyMCE會打破它。

但我已經複製這個tinyMCE文件形式的另一個項目,它的工作原理。所以我不知道wtf!

我有我的TinyMCE的設置是這樣的:

媒體/ JS/TinyMCE的

然後我在模板:

模板/管理/ APP_NAME /模型名稱/ change_form.html

這是我的change_form.html

{% extends "admin/change_form.html" %} 
{% load i18n %} 

{% block extrahead %}{{ block.super }} 
{% url 'admin:jsi18n' as jsi18nurl %} 
<script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script> 
{{ media }} 

<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery-1.6.4.min.js"></script> 
<script type="text/javascript" src="{{ MEDIA_URL }}js/tiny_mce/tiny_mce.js"></script> 
<script type="text/javascript"> 
function CustomFileBrowser(field_name, url, type, win) { 

    var cmsURL = "/admin/filebrowser/browse/?pop=2"; 
    cmsURL = cmsURL + "&type=" + type; 

    tinyMCE.activeEditor.windowManager.open({ 
     file: cmsURL, 
     width: 850, // Your dimensions may differ - toy around with them! 
     height: 650, 
     resizable: "yes", 
     scrollbars: "yes", 
     inline: "no", // This parameter only has an effect if you use the inlinepopups plugin! 
     close_previous: "no", 
    }, { 
     window: win, 
     input: field_name, 
     editor_id: tinyMCE.selectedInstance.editorId, 
    }); 
    return false; 
}; 

    tinyMCE.init({ 
     // add these two lines for absolute urls 
     remove_script_host : false, 
     convert_urls : false, 
     // General options 
     mode : "textareas", 
     theme : "advanced", 
     plugins : "safari,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media", 
     file_browser_callback: 'CustomFileBrowser', 
     // Theme options 
     theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|styleselect,formatselect,|,undo,redo,|,link,unlink,image,code", 
     theme_advanced_buttons3 : "", 
     theme_advanced_buttons4 : "", 
     theme_advanced_toolbar_location : "top", 
     theme_advanced_toolbar_align : "left", 
     // theme_advanced_statusbar_location : "bottom", 
     theme_advanced_resizing : false, 
     width:300, 
     height:300, 
    }); 

</script> 

{% endblock %} 

{% block object-tools %} 
{% if change %}{% if not is_popup %} 
    <ul class="object-tools"> 
    <li><a href="history/" class="historylink">{% trans "History" %}</a></li> 
    {% if has_absolute_url %} 
     <li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink"> 
      {% trans "View on site" %}</a> 
     </li> 
     <li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/html/" class="viewsitelink"> 
      {% trans "View source" %}</a> 
     </li> 
    {% endif%} 
    </ul> 
{% endif %}{% endif %} 
{% endblock %} 

即使如果我d在textareas.js中包含這一點,並將它包含在chnage_form.html extrahead塊中。

回答

0

嗯,我找出了錯在哪裏。也許有人遇到同樣的問題

問題是,當添加一個新行時,texarea不是由tinymce啓動的,因爲它只會在頁面加載時執行一次。完美的感覺,所以你需要添加一個新的行後再添加功能的te​​xtarea。

這是我做的:

change_form.html,已將此添加到文件

$(".add-row a").click(function() { 
     // this is the span that the current wsgi editor is in, so I remove it 
     $($(this).parent().prev().prev().find("span")[2]s).remove(); 
     // Now I display the original textarea 
     $(this).parent().prev().prev().find("textarea").show(); 
     // and Finaly lets add MCE control to this area. 
     tinyMCE.execCommand(
          'mceAddControl', 
          false, 
          $(this).parent().prev().prev().find("textarea").attr('id') 
         ); 
    }); 
+0

而另一件事的底部!從文檔就緒塊中刪除CustomFileBrowser表單,並將其添加到它之前,否則filebrowser將無法工作!geez這很令人沮喪 – Harry

+0

你能發佈完整的重寫模板文件嗎? –