2013-11-26 2 views
6

Я использую this jquery validation pluginКак проверить поля ввода с точкой в ​​имени с помощью плагина проверки jquery?

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

проверки не работает, но если я изменить имя title - проверка работы.

Я пробовал искать, но не смог найти средство для проверки полей с . на свое имя.

Пожалуйста, помогите

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> 

часть формы

<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> 
+0

Вам нужно добавить примеры кода на JQuery, который вы используете. – jammykam

+0

обновленный, смотрите. –

ответ

19

Вам нужно указать имена полей в qoutes. Из plugin documentation

Поля со сложными именами (скобки, точка)

Если у вас есть имя атрибут, как пользователь [имя], убедитесь, что поставить имя в кавычках. Подробнее см. В General Guidelines.

Образец в связанном Справочно:

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

удивительный, он сработал! –

Смежные вопросы