2017-05-02 41 views
0

我使用Summernote作爲wysiwyg編輯器,但我有一個問題。我的大部分文本編輯都是在代碼視圖中進行的,問題是如果您在代碼視圖中提交表單,編輯的文本不會保存。SummerNote wysiwyg編輯器保存在codeview不工作js/jquery

出於某種原因,我需要在代碼視圖和wysiwyg視圖之間切換以保存已編輯的文本。任何人都有如何解決這個問題的線索?

我已經看到這Not saving content while in code view? #127但它不適用於我。

這是我的代碼。

$(document).ready(function() { 
    $('#desc').summernote({ 
     height: 1000,     // set editor height 
     minHeight: null,    // set minimum height of editor 
     maxHeight: null,    // set maximum height of editor 
     focus: true,     // set focus to editable area after initializing summernote 
     codemirror: { 
      mode: 'text/html', 
      htmlMode: true, 
      lineNumbers: true, 
      theme: 'monokai' 
     }, 
     callbacks: { 
      onBlur: function() { 
      //should probably do something here 
      }, 
      onInit: function() { 
      console.log('Summernote is launched'); 
      $(this).summernote('codeview.activate'); 
      } 
     } 
    }); 
}); 

如果需要,這裏是html。

<textarea name="desc" id="desc" class="form-control" rows="40"></textarea> 

回答

3

試着做這樣的事情。

$(document).on("submit","#my-form-name",function(e){ 
    $("#desc").val($('#desc').code()); 
    return true; 
}); 


$(document).on("submit","#my-form-name",function(e){ 
    if ($('#desc').summernote('codeview.isActivated')) { 
     $('#desc').summernote('codeview.deactivate'); 
    } 
} 
+0

它似乎不適合我。問題是如果我嘗試加載表單上的任何東西,它會返回true,無論我做什麼。 –

+1

嘗試使用它。 ('#desc')。summernote('codeview.isActivated')){ $('#desc')。summernote('codeview.deactivate'); } –

+0

此解決方案的工作原理! –