jQuery-contextMenu icon indicating copy to clipboard operation
jQuery-contextMenu copied to clipboard

Checkbox change other option disabled value

Open Ztiwi opened this issue 9 years ago • 4 comments

Hi, im try to change the disabled value but i dont know how.

I have the next piece of code:

$(function(){
$.contextMenu({
        selector: '.context-menu-one', 
        callback: function(key, options) {
            var m = "clicked: " + key;
            window.console && console.log(m) || alert(m); 
        },
        items: {
          "changeCB": {
            name: "ChangeCheckBox", 
            type: 'checkbox', 
            selected: true,
            events: {
              click: function(e) {
              var $input = $(this);
              var $item = $input.closest('li');
              var data = $item.data();
              if ($input.prop('checked')){ 
                //WHEN CHECKED -> "DoOther" enable
              }else{
                //WHEN UNCHECKED -> "DoOther" disable
             }
           }
         }
        },
            "DoOther": {
                name: "Do Other function", 
                disabled: function(key, opt) { 
                    // this references the trigger element
                    return !this.data('cutDisabled'); 
                }
            }
        }
    });
});

Edit, put the code in a code block

Ztiwi avatar Jun 27 '17 08:06 Ztiwi

It would help if you can make a jsfiddle with this issue so i can reproduce is easily :)

bbrala avatar Jun 30 '17 14:06 bbrala

Here the jsfiddle: https://jsfiddle.net/a3m07bz7/

Thanks for the suggestion.

Ztiwi avatar Jul 02 '17 12:07 Ztiwi

I Have the same issue. Tested like done here, and i as well tried to put "this.data('cutDisabled', !this.data('cutDisabled'));" from the example. It works on callback but not on radio or checkbox events. Error is "basScripts.js:480 Uncaught TypeError: this.data is not a function" Please help! Here is another fiddle: https://jsfiddle.net/egxv8r7z/ I could create another one for "change" event and radio buttons, but the error is the same so...

boarsteas1 avatar May 15 '20 18:05 boarsteas1

It seems this is not the same in the context of that click event. In the relevant demo it uses the callback. I think this in your fiddle refers to the clicked element, so that is not the same at all.

So perhaps in your code check out whats in the e variable you get from function(e). You should be able to find the menu element in there which you can use. (the function should be function(opt) i think, which is the same argument as passed in disabled: function(key, opt).

bbrala avatar May 15 '20 19:05 bbrala