Jquery validation and TinyMCE 4.0.1



由于我更新到TinyMCE 4.0.1版,我的Jquery Validation不再工作。在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) {
            }           
        }

使用配置检测tinyMCE 4中的更改

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

如果你也面临这个问题,这意味着当你使用tinymce html编辑器时,所需的验证不起作用,所以我有一个解决方案,请遵循它,我希望你的问题得到解决,检查下面的代码使用nuget软件包在应用程序中安装tinymcejquery软件包创建一个这样的模型型号

    [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();
        }
    });

最新更新