本文介绍了带有TinyMCE字段的jQuery验证表单,该表单通过空值不给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用TinyMCE编辑器使用以下jQuery验证脚本: http://www.zinomen. com/test/validate.html

I have the following jQuery Validation script with the TinyMCE editor: http://www.zinomen.com/test/validate.html

当字段为空时,通过名字和姓氏会出错,但是在消息字段中不会出错.

By the firstname and lastname you get an error when the fields are empty, but at the message field you get no error.

我使用以下代码:

<script type="text/javascript">
$.validator.setDefaults({
    submitHandler: function() { alert('submitted, value of message = '+ tinyMCE.get('message').getContent()); }
});

$(document).ready(function() {

    // validate signup form on keyup and submit
    $("#signupForm").validate({
        rules: {
            firstname: {
                required: true,
                minlength: 2
            },
            lastname: {
                required: true,
                minlength: 2
            },
            message: {
                required: true,
                minlength: 15
            }
        },
        messages: {
            firstname: {
                required: "Please fill in your firstname",
                minlength: "Your firstname must consist of at least 2 characters"
            },
            lastname: {
                required: "Please fill in your lastname",
                minlength: "Your lastname must consist of at least 2 characters"
            },
            message: {
                required: "Please fill in your message",
                minlength: "Your message must consist of at least 15 characters"
            }
        }
    });
});
</script>

您通过以下方式获得的tinyMCE字段的值:tinyMCE.get('message').getContent();并具有<textarea id="message" name="message"></textarea>

The value of the tinyMCE field you get with: tinyMCE.get('message').getContent(); and in the form you have <textarea id="message" name="message"></textarea>

有人可以帮我,通过一个空的消息字段获得jquery验证错误吗?

Can anybody help me, to get by a empty message field also an error with jquery validate?

推荐答案

正在使用jsFiddle: http://jsfiddle.网络/jNJ2G/1/

working jsFiddle: http://jsfiddle.net/jNJ2G/1/

我使用了 TinyMCE jQuery插件并创建了jQuery验证的自定义规则

I used the TinyMCE jQuery plugin and created a custom rule for jquery validation

$('#message').tinymce({
                    // Location of TinyMCE script
                    script_url : 'http://www.zinomen.com/test/tiny_mce/tiny_mce.js',

                    // General options
                    theme : "advanced",
                    plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

                    // Theme options
                    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
                    theme_advanced_toolbar_location : "top",
                    theme_advanced_toolbar_align : "left",
                    theme_advanced_statusbar_location : "bottom",
                    theme_advanced_resizing : true,

                    // Example content CSS (should be your site CSS)
                    content_css : "css/content.css",

                    // Drop lists for link/image/media/template dialogs
                    template_external_list_url : "lists/template_list.js",
                    external_link_list_url : "lists/link_list.js",
                    external_image_list_url : "lists/image_list.js",
                    media_external_list_url : "lists/media_list.js",
            });

$.validator.addMethod("textInMce", function textInMce(value, element){
    return $('#message').html().length > 15;
}, "Please over 15 chars.");
$.validator.classRuleSettings.textInMce= { textInMce: true };

$("#signupForm").validate({
    rules: {
        firstname: {
            required: true,
            minlength: 2
        },
        lastname: {
            required: true,
            minlength: 2
        }
    },
    messages: {
        firstname: {
            required: "Please fill in your firstname",
            minlength: "Your firstname must consist of at least 2 characters"
        },
        lastname: {
            required: "Please fill in your lastname",
            minlength: "Your lastname must consist of at least 2 characters"
        }
    }
});
if ($("#signupForm").valid())
    alert('succes');

现在,

编辑这个有效的pastebin示例:) http://pastebin.com/cDJ9033C

Edit now this pastebin sample that does work :)http://pastebin.com/cDJ9033C

这篇关于带有TinyMCE字段的jQuery验证表单,该表单通过空值不给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 18:01