How to get id from the TabBar widget ?

Hi experts,

start to getting crazy with widgets , many different codes do not work when I run them, the below is one of them… it is straight forward… I got id as nil… any one knows why ?

[lua]

local widget = require “widget”

local function onBtnPress( event )
   print( "You pressed tab button: " , event.target.id )
end

local tabButtons = {
    {
        id = “list”,
        label = “New Leads”,
        defaultFile = “13-target.png”,
        overFile = “13-target-down.png”,
        width = 28, height = 28,
        onPress = onBtnPress,
        selected = true
    },
    {
     id = “saved”,
        label = “Saved”,
        defaultFile = “37-suitcase.png”,
        overFile = “37-suitcase-down.png”,
        width = 26, height = 26,
        onPress = onBtnPress
    },
    {
     id = “settings”,
        label = “Settings”,
        defaultFile = “19-gear.png”,
        overFile = “19-gear-down.png”,
        width = 26, height = 26,
        onPress = onBtnPress
    },
}

local tabs = widget.newTabBar {
    top = display.contentHeight-50,
    buttons = tabButtons
}

[/lua]

Regards

Abdul

Try this 

local function onBtnPress( event ) tab = event.target print( "You pressed tab button: " , tab.\_id) end

and yes… the widgets do have that effect on one.  :slight_smile:

wait wait wait :slight_smile: :slight_smile: :slight_smile:

Thanks man, it seems you are expert in widgets…
How does it work ? in the docs and other blogs they use id not _id … please explain to me to avoid future issues,

Regards
Abdulaziz

You are most welcome. No expert here. Just long term suffering thats all. Anyways, misery loves company so here we are!  :slight_smile:

There are lots of things not documented or exposed. The _view, _id etc type starting with _ are typically not meant for us to use. The _ means they are internal to the widgets and can be removed or changed with no warning. Not to say other things don’t ever change without warning but then thats a different topic for a different day. 

Here’s my suggestion. If you want to get more comfortable with the widgets certainly download the source off GitHub and walk yourself through them. It helps a lot. 

In this case I was able to quickly determine the variable (_id) using Glider’s debugger function. I placed a watch on event.target and was able to inspect it for the table members. Took all of 3 minutes. Not sure but you might be able to do this with the new Corona Editor as well. Not sure. In any case, debugging ability is very important. 

Hope all this helps. Good luck. 

Thanks sir, I appreciate your advice ,

Abdul

You are most welcome. Good luck with your project.

Try this 

local function onBtnPress( event ) tab = event.target print( "You pressed tab button: " , tab.\_id) end

and yes… the widgets do have that effect on one.  :slight_smile:

wait wait wait :slight_smile: :slight_smile: :slight_smile:

Thanks man, it seems you are expert in widgets…
How does it work ? in the docs and other blogs they use id not _id … please explain to me to avoid future issues,

Regards
Abdulaziz

You are most welcome. No expert here. Just long term suffering thats all. Anyways, misery loves company so here we are!  :slight_smile:

There are lots of things not documented or exposed. The _view, _id etc type starting with _ are typically not meant for us to use. The _ means they are internal to the widgets and can be removed or changed with no warning. Not to say other things don’t ever change without warning but then thats a different topic for a different day. 

Here’s my suggestion. If you want to get more comfortable with the widgets certainly download the source off GitHub and walk yourself through them. It helps a lot. 

In this case I was able to quickly determine the variable (_id) using Glider’s debugger function. I placed a watch on event.target and was able to inspect it for the table members. Took all of 3 minutes. Not sure but you might be able to do this with the new Corona Editor as well. Not sure. In any case, debugging ability is very important. 

Hope all this helps. Good luck. 

Thanks sir, I appreciate your advice ,

Abdul

You are most welcome. Good luck with your project.