简体   繁体   English

使用jQuery和验证插件验证textarea

[英]validate textarea with jquery and validation plugin

i use this plug as my text editor elrte 我使用这个插件作为我的文本编辑器elrte

when i tried to validate the text area within the jquery validation plugin it didn't work 当我尝试验证jquery验证插件中的文本区域时,它不起作用

var ArticleFormValidation = {};
                ArticleFormValidation.init =
                {
                    setArticleFormValidation: function()
                    {
                        //form validation rules
                        $("#ArticleForm").validate({
                            rules: {
                                ArticleTitle: "required",
                                slug: "required",
                                editor: "required"

                            },
                            messages: {
                                ArticleTitle: "Please enter article title",
                                slug: "Please enter article slug",
                                editor: "Please enter article body"
                            }


                        }); 
                    }
                }

it used to validate the first 2 fields only ArticleTitle,Slug and didn't validate the text area and when i removed the text editor code and get the field back as normal text area it works 它过去仅验证ArticleTitle,Slug的前两个字段,并且不验证文本区域,当我删除文本编辑器代码并将字段恢复为普通文本区域时,它可以工作

and this is the code for calling the text area 这是调用文本区域的代码

 var opts = {
                cssClass : 'el-rte',
                // lang     : 'ru',
                height   : 450,
                toolbar  : 'complete',
                cssfiles : ['../libs/elrte/css/elrte-inner.css']
            }
    $('#editor').elrte(opts);

what i need to do is to validate the text area when it becomes an editor because its useless to use it as normal text area 我需要做的是在它成为编辑器时验证文本区域,因为将其用作普通文本区域没有用

Can you validate it separately? 您可以单独验证吗?

if($('textareaid').val().Trim().Length == 0 ){

// alert

}

Alternatively as a hackaround you could have a hidden input as a text area and mimic the typing of the main text area into this field and validate this. 另外,作为一种变通办法,您可以将隐藏的输入作为文本区域,并模拟在该字段中键入主文本区域并进行验证。 The hidden input could be a textbox or text area. 隐藏的输入可以是文本框或文本区域。 See this jsfiddle 看到这个jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM