27
Views
8
Comments
Solved
Cannot read property '-1' of undefined error for Carousel widget
Service Studio Version
11.10.7 (Build 37468)

I am getting a "Cannot read property '-1' of undefined" error for Carousel widget.


I have a local variable which is type list of Images. (E.g. BusinessImages)

Based on an image which a user uploaded, I went to assign the uploaded image to the local variable.

For the carousel widget, I put the list source as my local variable.

Within the widget, there is an image placeholder and assigned the source E.g. BusinessImages.imageData.

When I test in my browser, the area where the carousel widget is supposed to be is empty, and if I click on that area, the error pops up.


Any idea what went wrong?


Screenshot20210131184925.jpg
2021-01-12 13-21-28
Kadu Borges
Solution

Hi SL,

On the OnInitializer event of the screen, you can append a NullBinary() on the image list. The default image will be shown for that and the error will not happen again.

The drawback of this solution is that you will have to remove the blank imagem when you add the first real image.

2018-10-29 08-31-03
João Marques
 
MVP

Hi Kadu,


Wouldn't it be best to in that case not display the carousel if the image list is empty?


In this case, you don't display anything and it is a more "clean" solution and easy to maintain.

Regards,
João

2021-01-12 13-21-28
Kadu Borges

Hi João,

Indeed, this seems to be a better solution. SL can put that If and, whether it is necessary, put a default image on the false branch. Thus, it will not need to handle issues on the list.

Nice thinking.

Regards

2021-01-12 13-21-28
Kadu Borges

Hi SL,

I haven't understand your construction. Could you please post the oml file or a print of you Widget tree?

Regards

UserImage.jpg
SL

Hi I just edited the post with an image of the widget tree

2021-01-12 13-21-28
Kadu Borges

I have made a test here and I got the same error as you when my Carousel is empty. I've tried using it with and without a list and the error message is the same.

2018-10-29 08-31-03
João Marques
 
MVP

Hi SL,


Can you confirm that your List inside CarouselItems has the variable BusinessImages and has the attribute disable-virtualization to True

UserImage.jpg
SL

Hi Joao, yes for the above. I just tried setting disable-virtualization to False and the carousel widget does appear :)


However, the images still do not appear in the carousel:

2021-01-12 13-21-28
Kadu Borges
Solution

Hi SL,

On the OnInitializer event of the screen, you can append a NullBinary() on the image list. The default image will be shown for that and the error will not happen again.

The drawback of this solution is that you will have to remove the blank imagem when you add the first real image.

2018-10-29 08-31-03
João Marques
 
MVP

Hi Kadu,


Wouldn't it be best to in that case not display the carousel if the image list is empty?


In this case, you don't display anything and it is a more "clean" solution and easy to maintain.

Regards,
João

2021-01-12 13-21-28
Kadu Borges

Hi João,

Indeed, this seems to be a better solution. SL can put that If and, whether it is necessary, put a default image on the false branch. Thus, it will not need to handle issues on the list.

Nice thinking.

Regards

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.