Hello,
1. I have a ListView component with checkboxes and template with anchor tag so that I can navigate to other pages when clicking it.
2. if I click on the link, the box gets checked instantly and it remains selected.
I would like to achieve the following logic:
1. Check box only gets selected if I ONLY click on the checkbox itself.
2. if I click on the link, it redirects me to the defined url.
here is some code:
<ListViewComponent
select={args => listItemSelectHandler(args)}
id='itemsList'
dataSource={visibleItems}
fields={{ id: 'id', text: 'Description', groupBy: 'isChecked' }}
showCheckBox={true}
sortOrder='Descending'
template={anchorTemplate}
/>
const anchorTemplate = (data) => {
return (<a target='_blank' rel='nofollow' href={`http://localhost:3000/item/${data.id}`} rel='noreferrer'>{data.Description}</a>);
}
I tried to solve it, but I could not manage to do so.
Thank you in advance.
|
const listItemSelectHandler = (args) => {
if (args.event.target.tagName == 'A') {
listObj.uncheckItem(args.item);
}
};
|
Dear Keerthana,
Thank you for your quick reply!
Indeed your solution is working great, I took a similar approach by checking the tab's visibility and toggling the checkbox because when you click the link, a new tab is set to open (with target='_blank'). Your solution is way more robust though!
For anyone that might want to achieve this as well, the provided solution accounts only for unchecked items, in order to account for checked too you need to toggle the checkbox rather than uncheck it always with something like this:
args.isChecked ? listObj.uncheckItem(args.item) : listObj.checkItem(args.item)
Have a great day!
Best regards.