【问题标题】:Jquery validation and TinyMCE 4.0.1Jquery 验证和 TinyMCE 4.0.1
【发布时间】:2013-07-10 23:38:02
【问题描述】:

自从我更新到 TinyMCE 4.0.1 版后,我的 Jquery 验证不再起作用。在版本 3.x 中,脚本可以正常工作。我可以使用 onchange_callback 函数吗...?

以前有没有人有过想法或同样的问题?

我的 TinyMCE 配置:

tinyMCE.init({
    language : "de",      
    mode : "textareas",
    theme : "modern",
    height: 250,

    statusbar : false,
    relative_urls : false,


    // update validation status on change
    onchange_callback: function(editor) {
        tinyMCE.triggerSave();          
        $("#" + editor.id).valid();     
    },

    // Theme options        
    ...

</script>

我的验证码:

    $(document).ready(function() {

        // update underlying textarea before submit validation          
        tinyMCE.triggerSave();

    ...
    ...

validator.focusInvalid = function() {
        // put focus on tinymce on submit validation    
        if( this.settings.focusInvalid ) {
            try {
                var toFocus = $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []);
                if (toFocus.is("textarea")) {
                    tinyMCE.get(toFocus.attr("id")).focus();
                } else {
                    toFocus.filter(":visible").focus();
                }               
            } catch(e) {
            }           
        }

【问题讨论】:

    标签: jquery validation tinymce


    【解决方案1】:

    通过配置检测到 tinyMCE 4 的变化

    tinymce.init({
        ...
        setup: function(editor) {
            editor.on('change', function(e) {
                console.log('change event', e);
            });
        }
    });
    

    【讨论】:

      【解决方案2】:

      如果您也遇到此问题,则表示您在使用 tinymce html 编辑器时所需的验证不起作用,所以我有一个解决方案,请遵循它,我希望您的问题得到解决,检查以下代码 使用 nuget 包在您的应用程序中安装 tinymce jquery 包 创建一个这样的模型 型号

          [Required(ErrorMessage = "Please enter About Company")]
          [Display(Name = "About Company : ")]
          [UIHint("tinymce_jquery_full"), AllowHtml]
          public string txtAboutCompany { get; set; }
      

      CSHTML 或查看

       <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 57px;">/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();
              }
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-15
        相关资源
        最近更新 更多