[英]How to validate input fields with a dot in name using the jquery validation plugin?
I'm using this jquery validation plugin 我正在使用这个jquery验证插件
<s:textfield cssClass="form-control input-default" name="contest.title" id="title" placeholder="Enter Title"
/>
Validation doesn't work for this, but if I change the name to title
- validation works. 验证不适用于此,但如果我将名称更改为
title
- 验证工作。
I tried searching, but couldn't find a means to validate fields with a .
我试过搜索,但找不到用于验证字段的方法
.
in their name. 以他们的名义。
Please help 请帮忙
Update 更新
Script 脚本
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#contestform").validate({
submitHandler: function(form) {
// return false; // block the default submit action
},
rules: {
title: {
required: true
},
link: {
required: true
},
startdt: {
required: true
},
enddt: {
required: true
},
descr: {
required: true
},
},
messages: {
title: "Please enter a title",
link: "Please enter the sponser redirection link",
startdt: "Please select start date",
enddt: "Please select end date",
descr: "Please enter description"
}
});
});
</script>
Part of the form 部分表格
<form action="" enctype="multipart/form-data" method="post" id="contestform">
<s:hidden name="option" value="option"/>
<s:hidden name="contest.idcontest"/>
<div class="form-group">
<label for="title">Title</label>
<s:textfield cssClass="form-control input-default" name="contest.title" id="title" placeholder="Enter Title"
/>
</div>
You need to put the field names in qoutes. 您需要将字段名称放在qoutes中。 From the plugin documentation
从插件文档
Fields with complex names (brackets, dots)
名称复杂的字段(括号,点)
When you have a name attribute like user[name], make sure to put the name in quotes.
当您具有类似user [name]的名称属性时,请确保将名称放在引号中。 More details in the General Guidelines .
一般准则中的更多细节。
The sample in the linked reference: 链接参考中的示例:
$("#myform").validate({
rules: {
// no quoting necessary
name: "required",
// quoting necessary!
"user[email]": "email",
// dots need quoting, too!
"user.address.street": "required"
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.