cancel
Showing results for 
Search instead for 
Did you mean: 

Bar id using this.byId() gives error when try to set its vibility

Former Member
0 Kudos
351

hi,

i've a bar declaration in my xml.view like below:

<m:Bar id="idBar"  visible="false">
<m:contentRight >
<m:Button
id = "idBtnAddCart"
text = "Submit"
type = "Emphasized"
icon = "sap-icon://cart"
press = "pressSubmit"
visible="true"
>
</m:Button>
</m:contentRight>
</m:Bar>

and i've below on one of the actions:

this.byId("idBar").setVisible(true);

and when clicked on the action button, it shows me:

Uncaught TypeError: Cannot read property 'id' of undefined

can i set visibility on BAR <Mobile>? is it valid to do that? other ui controls works.. but not BAR.

i've anyways handled it in a different way, but wanted to know why its giving error.

Accepted Solutions (0)

Answers (2)

Answers (2)

pfefferf
Active Contributor
0 Kudos

Hi,

within your controller method you have to use this.getView().byId("idBar").setVisible(true). So the unique ID support is also considered.

Best regards,

Florian

Former Member
0 Kudos

hi Florian, i've tried this before, didnt worked. tnx

SandipAgarwalla
Active Contributor
0 Kudos

since this is an xml view, this.getView().byId("idBar") will not work....xml view adds a prefix to the control ids..

you have to use

this.getView().byId("viewID--idBar")  , where viewID is the id you have assigned to the view somewhere


if you are in the controller, you should do this.getView().byId("idBar") ...this will also work..if it does not work, then check for 'this' ..that could be the local event instead of the controller...



Former Member
0 Kudos

hi Sandip, i did tried using the viewID & BarID combination. not sure why even this is not working..! gives me same error. this.byId("id of controller") - this is working for other ui controls.. only have problem with BAR. fyi, all my views are xml and inside shell.

pfefferf
Active Contributor
0 Kudos

Maybe you can post a sample of your code which is not working.

kai2015
Contributor
0 Kudos

Please paste the relevant code to JS Bin. So we can help you.

SergioG_TX
Active Contributor
0 Kudos

try sap.ui.getCore().byId("yourId")

Former Member
0 Kudos

i get below error when used: sap.ui.getCore().byId("yourId").setVisible("true"); Cannot read property 'setVisible' of undefined

SergioG_TX
Active Contributor
0 Kudos

"yourID" is the id of your control not the string "yourId".

if your control id is "listabc" then change "yourId" to "listabc"

Former Member
0 Kudos

ya i was using the actual control id itself.