Saturday, January 1, 2022

[FIXED] No event listener for x-editable table elements

Issue

I have a dynamic table, with one column set to have editable elements. Once the page is rendered, I can edit the entry in the first row, but thereafter none of the other rows have event listeners for the id: name. I can't understand why. Here is my code:

$(document).ready(function(){
    //toggle `popup` / `inline` mode
    $.fn.editable.defaults.mode = 'popup';     

    //make name editable
    $('#name').editable();
    ... });

      <tbody>
        <?php foreach ($action_lists as $list_item) {
          echo "<tr>";
              echo "<td> <a href=\"#\" id=\"name\" data-pk=\"{$list_item["ActionList"]["list_index"]}\" data-url=\"/post\" data-type=\"text\" data-placement=\"right\" data-title=\"Enter new name.\" class=\"editable editable-click\">{$list_item["ActionList"]["name"]}</a></td>";
          echo "</tr>";
        }?>
      </tbody>

Solution

$('#name') will query the document based on id so it will return the first matched element so just use class name instead of id and use $(".name"), Then it will apply to all the element



Answered By - Mukesh Agarwal

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.