【问题标题】:jEditable validation not workingjEditable 验证不起作用
【发布时间】:2012-03-24 12:51:57
【问题描述】:

我想通过 jEditable 使用 jQuery 验证。在这里,我在类似这样的 while 循环中从我的数据库中回显一个表。

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

这是我正在使用的带有 jQ​​uery 验证代码的 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 运行良好。但是验证的东西不起作用。这个验证码正确吗?

【问题讨论】:

    标签: jquery jquery-validate jeditable edit-in-place


    【解决方案1】:

    引用 OP:“这个验证码正确吗?”

    事实并非如此。在插件参数中定位的input 元素的名称应该只引用forminput 元素的name 属性,而不是table 中单元格的id

    AFAIK,jQuery Validation Plugin 旨在仅针对 &lt;form&gt; 中包含的 &lt;input&gt; 元素。您的代码中都没有。

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

    【讨论】:

    • Sparky672 - 那么如何使用这个 jEditable 进行验证?请帮助:)
    • @collozziza,这不是你最初问的......我只知道你不能使用验证插件,除非你在 form 元素中有 input 元素。也许您需要发布一个关于如何正确使用 jEditable 进行验证的新问题。
    • Sparky672 - 这就是我要问的 :) 如何使用 jEditable 进行验证。这是我的代码。当您单击或右击 dblclick 时,jEditable 会创建一个 input 元素?
    • @collozziza,我已经回答了你原来的问题。所以现在我说你应该发布一个全新的问题,熟悉 jEditable 的人可以回答它。请记住,我们不是在这里从头开始构建您的整个项目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 2011-10-02
    相关资源
    最近更新 更多