0

I wanna use jQuery validation with jEditable. Here, I'm echoing a table from my database in a while loop something like this.

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

And this is the jEditable script with jQuery validation codes I'm using.

$("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',

});
});

Here, jEditable is working perfectly. But validation thing is not working. Is this validation code correct?

blahdiblah
  • 33,069
  • 21
  • 98
  • 152

1 Answers1

1

Quote OP: "Is this validation code correct?"

It is not. The names of the input elements targeted within the plugin's parameters should only reference the name attribute of an input element within a form, not the id of a cell within a table.

AFAIK, the jQuery Validation Plugin was designed to only target <input> elements contained within a <form>. You have neither in your code.

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

Sparky
  • 98,165
  • 25
  • 199
  • 285
  • Sparky672 - Then how to do validation with this jEditable? Pls help :) – collozziza Mar 27 '12 at 01:30
  • @collozziza, that's not what you originally asked... I just know that you cannot use the Validation plugin unless you have `input` elements within a `form` element. Perhaps you need to post a new question about how to properly do Validation with jEditable. – Sparky Mar 27 '12 at 02:00
  • Sparky672 - Thats what i'm asking :) How to do validation with jEditable. This is the code i have. jEditable creates an `input` element when u click or dblclick right? – collozziza Mar 27 '12 at 02:19
  • @collozziza, I have already answered your original question. So now I am saying that you should post a totally new question where people familiar with jEditable can answer it. Just remember that we are not here to construct your whole project from scratch. – Sparky Mar 27 '12 at 02:23