Skip to content
This repository was archived by the owner on Aug 14, 2021. It is now read-only.
This repository was archived by the owner on Aug 14, 2021. It is now read-only.

Using setEntry with an object caches the first modification executed in the beforeOpen method. #33

@tponthieux

Description

@tponthieux

The setEntry functionality can be used with a string or an object input.

$("#details").contextmenu("setEntry", "opt1", {title: titleText});
$("#details").contextmenu("setEntry", "opt2", titleText);

This is the first right click. Things seem to be working as expected.
image

The second right click shows that there is something wrong. The title modification from the first right click is present in option 1.
image

Here is a working example:

<link href="js/lib/jquery-ui-1.10.3/css/smoothness/jquery-ui-1.10.3.custom.css" type="text/css" rel="stylesheet" />
<script src="js/lib/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="js/lib/jquery-ui-1.10.3/js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>
<script src="js/lib/jquery.ui-contextmenu.js" type="text/javascript"></script>

<style type="text/css">
  .hasmenu {
    border: 1px solid #008;
    margin: 3px;
    padding: 5px;
    width: 30px;
  }
  .ui-widget{
    font-size: .8em;
  }
  table, td {
  border: 1px solid dimgray;
  }
</style>

<script type="text/javascript">
  $(document).ready(function () {

    function action (event, ui) {
      console.log(ui.target);
    };

    $("#details").contextmenu({
      delegate: ".hasmenu",
      menu: [
        {title: "Option 1 title", cmd: 'opt1', action: action},
        {title: "Option 2 title", cmd: 'opt2', action: action}
      ],
      beforeOpen: function(event, ui) {
        var titleText = 'record ' + ui.target.parent().attr('record');
        $("#details").contextmenu("setEntry", "opt1", {title: titleText});
        $("#details").contextmenu("setEntry", "opt2", titleText);
      }
    });

  });
</script>

<table id="details" class="table">
  <thead>
    <tr>
      <th>Id</th>
      <th>File Name</th>
    <tr />
  </thead>
  <tbody>
    <tr record="1" class="hasmenu">
      <td>1</td>
      <td>Record 1</td>
    </tr>
    <tr record="2" class="hasmenu">
      <td>2</td>
      <td>Record 2</td>
    </tr>
  </tbody>
</table>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions