Popup Event Handling

Trying to handle click event of items within a popup list.

Option 1 calls the popup view and its list as a variable. It fails.

Option 2 calls the popup view and its list via webix.ui. It works.

I would like to use Option 1 in my app. Can you advise on why Option 1 fails but option 2 works?

Thanks

http://webix.com/snippet/6b90922c

Hey Charlie12,

Here’s the solution.

Your datastructure (testPopVar) was not registered with the framework, hence the routing failed. The Webix framework can’t lookup the Popup code to call if it isn’t registered using webix.ui ().

This works:

//Option 1
var testPopVar = webix.ui({
    view: "popup",
    id: "menuPop1",
    padding: 0,
    width: 100,
    body: {
        view: "list",
        id: "menuList1",
        autoheight: true,
        borderless: true,
        data: [
            {id: "popup1a", value: "Item 1a"},
            {id: "popup1b", value: "Item 1b"}
        ]
    }
}); 


//Main code    
webix.ui({
    container: "layout_div",
    id: "layout",
    width: 600,
    rows: [
        {
            view: "toolbar",
//              margin: 20,
//              padding: 20,
            cols: [
                {view: "icon", icon: "cog", id: "btnPopup1", popup: testPopVar},
                {view: "icon", icon: "cog", id: "btnPopup2", popup: "menuPop2"}
            ]
        }
      ]
 });
  
//Option 2
webix.ui({
    view: "popup",
    id: "menuPop2",
    padding: 0,
    width: 100,
    body: {
        view: "list",
        id: "menuList2",
        autoheight: true,
        borderless: true,
        data: [
            {id: "popup2a", value: "Item 2a"},
            {id: "popup2b", value: "Item 2b"}
        ]
    }
});


//Event Handling

//Option 1
$$("menuList1").attachEvent("onItemClick", function (id) {
    var test25 = this.getItem(id).value;  
    webix.message(id + " clicked, its value is " + test25);
});

//Option 2 - this works
$$("menuList2").attachEvent("onItemClick", function (id) {
    var test26 = this.getItem(id).value;  
    webix.message(id + " clicked, its value is " + test26);
});

Got it - might have known it was something simple - thanks McNoober