Page 1 of 1

Click Event in a Carousel

Posted: Tue Jul 05, 2016 12:53 am
by billcross
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 ?

Re: Click Event in a Carousel

Posted: Tue Jul 05, 2016 9:44 am
by Stewart Marshall
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.

Re: Click Event in a Carousel

Posted: Tue Jul 05, 2016 7:43 pm
by billcross
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)

Re: Click Event in a Carousel

Posted: Tue Jul 05, 2016 9:02 pm
by Stewart Marshall
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.

Re: Click Event in a Carousel

Posted: Tue Jul 05, 2016 9:36 pm
by billcross
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.

Re: Click Event in a Carousel

Posted: Wed Jul 06, 2016 9:02 am
by Stewart Marshall
It should have been .Design and NOT .Part

My mistake. Sorry for the confusion.

I've updated my previous comment

Re: Click Event in a Carousel

Posted: Wed Jul 06, 2016 9:13 am
by Stewart Marshall
The ItemClick and ItemDoubleClick events will be available in SP1

Re: Click Event in a Carousel

Posted: Thu Jul 07, 2016 1:30 am
by billcross
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 ?

Re: Click Event in a Carousel

Posted: Thu Jul 07, 2016 11:40 am
by Stewart Marshall
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