Click Event in a Carousel
Click Event in a Carousel
I created a copy of xDemoCarouselDesign and I am using it to display various types of product information. I would like to open a detail page when the user clicks a particular item but I am unable to access the click event for the carousel. Is there a way to do this ?
- Stewart Marshall
- Posts: 417
- Joined: Thu Nov 05, 2015 5:25 pm
Re: Click Event in a Carousel
There are a couple of ways of handling this situation.
The first technique, and best practice, is to create a shared component instance that is used by the reusable parts in the carousel. The parts invoke a "DoSomething" method in the shared object and it can fire an event that other reusable parts can respond to. This is an excellent technique for managing the interaction of multiple reusable parts used to construct complex UIs.
The alternative is that a user defined event is fired and detected in the reusable part containing the Carousel itself.
http://vlforum.lansa.com.au/viewtopic.php?f=3&t=29&p=52 describes a very similar scenario.
The first technique, and best practice, is to create a shared component instance that is used by the reusable parts in the carousel. The parts invoke a "DoSomething" method in the shared object and it can fire an event that other reusable parts can respond to. This is an excellent technique for managing the interaction of multiple reusable parts used to construct complex UIs.
The alternative is that a user defined event is fired and detected in the reusable part containing the Carousel itself.
http://vlforum.lansa.com.au/viewtopic.php?f=3&t=29&p=52 describes a very similar scenario.
Re: Click Event in a Carousel
I tried using the method described in the topic but had an issue getting it to work.
I used a define statement like the one below to access the current carousel
Define_Com Class(#HLWEBCAR) Name(#CurrentCarousel) Reference(*Dynamic)
but when I tried to assign it to the current one #CurrentCarousel <= #HomeCarousel.Currentitem *As #HLWEBCAR at run time it fails.
Is this because the definition for the HomeCarousel looks like this
Define_Com Class(#PRIM_CARO<#HLWEBCAR>) Name(#HomeCarousel)
I used a define statement like the one below to access the current carousel
Define_Com Class(#HLWEBCAR) Name(#CurrentCarousel) Reference(*Dynamic)
but when I tried to assign it to the current one #CurrentCarousel <= #HomeCarousel.Currentitem *As #HLWEBCAR at run time it fails.
Is this because the definition for the HomeCarousel looks like this
Define_Com Class(#PRIM_CARO<#HLWEBCAR>) Name(#HomeCarousel)
- Stewart Marshall
- Posts: 417
- Joined: Thu Nov 05, 2015 5:25 pm
Re: Click Event in a Carousel
I assume the error is something like "Failure while casting object of type PRIM_CARO.CarouselItem to type HLWEBCAR"
The assignment should read
#CurrentCarousel <= #HomeCarousel.Currentitem.Design *As #HLWEBCAR
If you only refer to CurrentItem, you're referring to the underlying list item in the carousel. By attaching .Design on the end, the reference is the reusable part instance.
The assignment should read
#CurrentCarousel <= #HomeCarousel.Currentitem.Design *As #HLWEBCAR
If you only refer to CurrentItem, you're referring to the underlying list item in the carousel. By attaching .Design on the end, the reference is the reusable part instance.
Last edited by Stewart Marshall on Wed Jul 06, 2016 9:00 am, edited 2 times in total.
Re: Click Event in a Carousel
I had tried that and got the errors below
Feature name Part is not a member of component type PRIM_CARO.CarouselItem.
#HomeCarousel.Currentitem.PART *As #HLWEBCAR is not a component.
Feature name Part is not a member of component type PRIM_CARO.CarouselItem.
#HomeCarousel.Currentitem.PART *As #HLWEBCAR is not a component.
- Stewart Marshall
- Posts: 417
- Joined: Thu Nov 05, 2015 5:25 pm
Re: Click Event in a Carousel
It should have been .Design and NOT .Part
My mistake. Sorry for the confusion.
I've updated my previous comment
My mistake. Sorry for the confusion.
I've updated my previous comment
- Stewart Marshall
- Posts: 417
- Joined: Thu Nov 05, 2015 5:25 pm
Re: Click Event in a Carousel
The ItemClick and ItemDoubleClick events will be available in SP1
Re: Click Event in a Carousel
This now works but I'm having an issue properly detecting the transition from one item of the carousel to the next. I thought ItemGotFocus would be the event to use but it does not seem to fire when the carousel item is changed. What event should be used ?
- Stewart Marshall
- Posts: 417
- Joined: Thu Nov 05, 2015 5:25 pm
Re: Click Event in a Carousel
It seems that you've discovered a bug. ItemGotFocus isn't firing correctly for Carousel in the GA.
This will be resolved in SP1.
In the meantime, a simple shared object will do the job for you. In the attached export, I've modified the sample to include a third object (xDemoWebCarouselHandler). This is defined in both the design and the carousel as Scope(*Application) meaning that there can only ever be one instance of it.
The design executes a method in the Handler, which in turn fires an event. This is detected by the Carousel which in this case shows the ID, but could of course do whatever you want.
Using shared objects to simplify communications between multiple parts is an extremely powerful feature and is very much worth getting to grips with.
regards
This will be resolved in SP1.
In the meantime, a simple shared object will do the job for you. In the attached export, I've modified the sample to include a third object (xDemoWebCarouselHandler). This is defined in both the design and the carousel as Scope(*Application) meaning that there can only ever be one instance of it.
The design executes a method in the Handler, which in turn fires an event. This is detected by the Carousel which in this case shows the ID, but could of course do whatever you want.
Using shared objects to simplify communications between multiple parts is an extremely powerful feature and is very much worth getting to grips with.
regards
- Attachments
-
- Carousel.zip
- (11.22 KiB) Downloaded 1668 times