How to check input fields with a dot in a name using jquery validation plugin?

I use this jquery validation plugin

<s:textfield cssClass="form-control input-default" name="contest.title" id="title" placeholder="Enter Title" /> 

Validation does not work for this, but if I change the name to title , validation works.

I tried to search, but could not find a tool to check the fields with . 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> 
+6
source share
1 answer

You need to specify the field names in qoutes. From the plugin documentation

Fields with complex names (brackets, periods)

If you have a name attribute, such as user [name], be sure to set the name in quotation marks. See the General Guidelines for details.

Sample link:

 $("#myform").validate({ rules: { // no quoting necessary name: "required", // quoting necessary! "user[email]": "email", // dots need quoting, too! "user.address.street": "required" } }); 
+20
source

Source: https://habr.com/ru/post/958869/


All Articles