2014-01-10 201 views
0

我有一個表格自定義隱藏字段驗證:使用jQuery驗證插件

<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文本編輯字段,這意味着這個字段的值將不會由ID檢索=「描述「和名稱是自動完成字段,所以當我把上述驗證規則:

> $("#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; } 
>   }); 
} 

**

確認消息將顯示在下面的隱藏字段,根據您的需要放置它們。