2012-03-24 142 views
0

我想用jEditable使用jQuery驗證。在這裏,我在一個while循環中回顯了我的數據庫中的表格。jEditable驗證不起作用

<table id="example" class="display" cellspacing="0" border="0"> 
<thead> 
    <tr> 
    <th> 
    Name 
    </th> 
    <th> 
    Phone 
    </th> 
</tr> 
</thead> 
<tbody> 
    <tr> 
    <td class="items" userid="'.$row['id'].'" id="name">'.$row['name'].'</td> 
    <td class="items required" userid="'.$row['id'].'" id="phone">'.$row['phone'].'</td> 
    </tr> 
</tbody> 
</table> 

這就是我正在使用jQuery驗證代碼的jEditable腳本。

$("td.items").each(function(index) {  
$(this).editable("handler.php", { 

onsubmit: function(settings, td) { 
    var input = $(td).find('input'); 
    $(this).validate({ 
     rules: { 
      phone: { 
       number: true, 
      } 
     }, 
     messages: { 
      phone: { 
       number: 'Only numbers are allowed', 

      } 

     }, 
    }); 
    return ($(this).valid()); 
}, 

submitdata : {userid: $(this).attr('retailerid')}, 
indicator : "<img src='images/indicator.gif'>", 
tooltip : "Doubleclick to edit...", 
event  : "dblclick", 
onblur : "submit", 
name : 'newvalue', 
id : 'elementid', 

}); 
}); 

在這裏,jEditable工作正常。但驗證的東西不起作用。這個驗證碼是否正確?

回答

1

報價OP:「這個驗證碼是否正確?」

它不是。在插件參數中定位的input元素的名稱應僅引用form中的input元素的name屬性,而不引用table中的單元格的id

AFAIK,jQuery Validation Plugin被設計爲僅針對<form>中包含的<input>元素。你在代碼中都沒有。

http://docs.jquery.com/Plugins/Validation/validate#toptions

+0

Sparky672 - 那麼如何使用此jEditable進行驗證?請幫助:) – collozziza 2012-03-27 01:30:56

+0

@collozziza,這不是你最初的問題......我只知道你不能使用Validation插件,除非你在'form'元素中有'input'元素。也許你需要發佈一個關於如何正確使用jEditable進行驗證的新問題。 – Sparky 2012-03-27 02:00:25

+0

Sparky672 - 這就是我問:)如何使用jEditable進行驗證。這是我的代碼。當你單擊或右鍵單擊時,jEditable會創建一個'input'元素? – collozziza 2012-03-27 02:19:27