22
Views
15
Comments
Solved
List item highlighting is not working under nested accordions.
Application Type
Mobile, Reactive

Hi ,

I have list of accordions and under each accordion there is a list of items . I am using below code to keep list items highlighted on click ,




and below is widget hierarchy ,


Problem: Its highlighting only first 2 list items  of first 2 accordions .Highlighting is not working for other list items of first 2 accordions and not able to highlight even single list item other than first two accordions.

Any resolutions are appreciated .

Thanks,

Santosh

2020-05-21 04-56-19
Santosh Chanveer
Solution

Hi ,

This scenario is working after using same script on "Initialized " handler of accordion .I am yet need to check whether the JavaScript event will be registered along with each list number  of accordions.


Thanks,

Santosh 

2022-12-30 07-28-09
Navneet Garg
Solution

Rather than registering new click event I am using ListItem1 click event. It is more easy and clean implementation. Please check

Custom-Accordion_Update.oml
2022-12-30 07-28-09
Navneet Garg
Solution

Another solution without javascript using only css and click event

Custom-Accordion_Update_WithoutJS.oml
2026-01-28 16-57-48
Mihai Melencu
Champion

Hi Santosh,

Are you trying to highlight only one item per list or multiple item per list?

2020-05-21 04-56-19
Santosh Chanveer

One item at a time from all accordions .


2026-01-28 16-57-48
Mihai Melencu
Champion

Hi, an alternative for you is to create a local variable called SelectedId of type Entity.Id. 

Create a Client Action with an input parameter for SelectedId with type Entity.Id and assign that to the OnClick event of the ListItem. 

In this action assign the value of the input parameter to the local variable.

Then in the attributes  of the ListItem add dynamic styling based on the SelectedId.

Also make sure to add !important to your CSS class for the property you want to override.

2020-05-21 04-56-19
Santosh Chanveer

Hi Melencu,

Thanks for suggestion but I think this solution always requires unique reference for each list row . And it will not work for duplicate record reference . 


Thanks,

Santosh

2022-12-30 07-28-09
Navneet Garg

Are you able to check that class is added to the element or not use chrome developer tool to check?

can you share you oml ? or test page link where I can check html and js ?

2020-05-21 04-56-19
Santosh Chanveer

Hi Navneet ,

No, class is not being added to other list items than first two . Also in script I am able to get only 2 accordion objects with 2 list items each .


Thanks,

Santosh

2022-12-30 07-28-09
Navneet Garg

it means your selector is not working properly. I will check oml and let you know.

2020-05-21 04-56-19
Santosh Chanveer

Please find OML for reference,



Thanks,

Santosh

Custom-Accordion.oml
2025-11-25 13-20-12
Tamirys Silva Barina

Hi @Santosh Chanveer ,

I usually achieve this without JavaScript by using a variable to check if the item is selected and adding a new class to the list: If(IsSelected, "highlighted-item", ""). 

 However, if your accordion is inside a web block that is inside a screen, the CSS may be overridden by the screen’s CSS. If that’s the case, you would need to apply the styling at the screen level.

Regards,

Tami

2020-05-21 04-56-19
Santosh Chanveer

Hi Tami,

Can you suggest how to remove previously selected list item highlighting  using variable . Are you referring to use extra attribute called is-highlighted  to each list  item and on selection of one list item , we can update that value for other list items ?


Thanks,

Santosh

2025-11-25 13-20-12
Tamirys Silva Barina

Yes! You can use an additional attribute (like is-highlighted) to track the selection state for each item and update it when a new item is selected. Then, you can apply the CSS to the selected items by using a class.


2020-05-21 04-56-19
Santosh Chanveer
Solution

Hi ,

This scenario is working after using same script on "Initialized " handler of accordion .I am yet need to check whether the JavaScript event will be registered along with each list number  of accordions.


Thanks,

Santosh 

2022-12-30 07-28-09
Navneet Garg
Solution

Rather than registering new click event I am using ListItem1 click event. It is more easy and clean implementation. Please check

Custom-Accordion_Update.oml
2022-12-30 07-28-09
Navneet Garg
Solution

Another solution without javascript using only css and click event

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