2012-07-07 102 views
2

我想使用tinymce的getContent()來做一個自定義的驗證規則,我該如何做到這一點與jQuery驗證?我需要將規則應用於使用tinymce格式化的textarea。tinyMCE jQuery表單驗證

驗證:http://bassistance.de/jquery-plugins/jquery-plugin-validation/

$("#element").click(function(e) { 

    console.log(tinyMCE.activeEditor.getContent()); 

    $("#someForm").validate({ 
     rules: {   
      title: { 
       required: true 
      } 
     } 
    }); 

}); 

我想只是使用JavaScript的用的getContent()一點點,因爲它看起來像有一樣多的努力創造一種變通方法來獲得jQuery驗證與TinyMCE的工作。想想可能的解

回答

0

你好,如果你沒有得到在形式的客戶端驗證提交時間你用tinymce試試這個代碼 假設你有兩個html編輯器1是txtAboutCompanyan d 2是txtProductinfo

這是客戶端代碼

<div class="divclass"> 
    @Html.LabelFor(model => model.txtAboutCompany, new { @class = "required" }) 
    @Html.EditorFor(model => model.txtAboutCompany) 
    <span class="field-validation-error" id="AC" style="margin:9px 0 0 157px;"></span> 
</div> 

這是jQuery的

$("#BusinessProfile").click(function() { 
     var aboutC = $("#txtAboutCompany").val() 
     var pinfo = $("#txtProductinfo").val(); 
     if (aboutC == "" && pinfo == "") { 
      $("#AC").append("").val("").html("Please enter about company") 
      $("#PI").append("").val("").html("Please enter product information") 
      $("#bpform").valid(); 

      return false; 
     } else if (aboutC == "") { 
      $("#PI").append("").val("").html("") 
      $("#AC").append("").val("").html("Please enter about company") 
      $("#txtAboutCompany").focus(); 

      $("#bpform").valid(); 
      return false; 
     } else if (pinfo == "") { 
      $("#AC").append("").val("").html("") 
      $("#PI").append("").val("").html("Please enter product information") 
      $("#txtProductinfo").focus(); 
      $("#bpform").valid(); 

      return false; 
     } 
     else { 
      $("#AC").append("").val("").html(""); 
      $("#PI").append("").val("").html(""); 
      //return true; 
      $("#bpform").validate(); 
     } 
    }); 

你可以得到你的表單都需要驗證提交時間

我知道這是不正確的方式,但你可以做到這一點。

+0

http://stackoverflow.com/questions/11371966/tinymce-jquery-form-validation/22170043#22170043 – 2014-03-04 11:09:14

0
function tinymceValidation() { 
    var content = tinyMCE.activeEditor.getContent(); 
    if (content === "" || content === null) { 
     $("#questionValid").html("<span>Please enter question statement</span>"); 
    } else { 
     $("#questionValid").html(""); 
    } 
} 

tinymce.activeEditor.on('keyup', function (e) { 
    debugger; 
    tinymceValidation(); 
}); 

$(form).submit(function (e) { 
    tinymceValidation(); 
}); 
+0

請仔細閱讀[這](http://meta.stackoverflow.com/a/303605/ 4284627)關於僅有代碼的答案並編輯您的答案以添加解釋。 – 2017-01-03 11:28:02