使用 jQuery 验证插件自定义隐藏字段验证
Posted
技术标签:
【中文标题】使用 jQuery 验证插件自定义隐藏字段验证【英文标题】:Custom hidden field validation using jQuery validate plugin 【发布时间】:2014-01-29 00:59:27 【问题描述】:我有一个表格:
<form id="actualForm" action="" novalidate="novalidate">
<div class="o-group">
<input placeholder="Title" id="name" name="title">
</div>
<div class="o-group">
<textarea id="description">Enter Description </textarea>
</div>
<div class="o-group">
<input placeholder="Name" id="name" name="name">
</div>
</form>
在上面的表单描述字段是nic Text Editor字段,这意味着该字段的值不会被id="description" 检索并且名称是自动完成字段,所以当我为上面设置验证规则时:
> $("#actualForm").validate(
> rules:
> title:
> required: true,
> minlength: 2
> ,
> description:
> required: true,
> minlength: 2
>
> ,
> messages:
> title:
> required: "Please enter a title",
> minlength: "At least 2 characters"
> ,
> description:
> required: "Please enter a description",
> minlength: "At least 2 characters"
>
> ,
> submitHandler: function(form) return false;
> );
现在当我调用 object.validate();它不验证描述字段以及如何验证名称字段?
【问题讨论】:
【参考方案1】:**
function validateForm()
// Create hidden input fields for description and name
// Assign values to them as:
$("hiddenDescription").val($(".nicEdit-main").html());
$("hiddenName").val("take value from autocomplete");
$("#actualForm").validate(
ignore:"",
> rules:
> title:
> required: true,
> minlength: 2
> ,
> description:
> required: true,
> minlength: 2
>
> ,
> messages:
> title:
> required: "Please enter a title",
> minlength: "At least 2 characters"
> ,
> description:
> required: "Please enter a description",
> minlength: "At least 2 characters"
>
> ,
> submitHandler: function(form) return false;
> );
**
验证信息将显示在隐藏字段下方,根据需要放置。
【讨论】:
以上是关于使用 jQuery 验证插件自定义隐藏字段验证的主要内容,如果未能解决你的问题,请参考以下文章