Issue with button having to be clicked twice using onClick

Hello,
I am experiencing something I believe to be rather interesting. I am sure it is something in the code I am using, but don’t know why. Help would be greatly appreciated!

I have a repeater that is pulling contact details from a database. In that repeater I have a button that links to the email address that once clicked causes the clients email program to open a new email.

It all works, except for some reason I have to click on the button twice in order for it to open the new email. I don’t have it set for Dbl_Click, so I can’t figure out why I have to click twice. The second click can even be several seconds after the first click and it will still open, but never on just one click.

Here’s the code I am using:

import wixData from 'wix-data';
$w.onReady(function () {});
export function button10_click(event, $w) {
 const email = $w('#dataset1').getCurrentItem().emailAddress;
    $w("#button10").link = 'mailto:' + email;
}

Are you sure the propierties are set onClick?

If so delete the function from the propertied panel and then add tem again.

The button is only assigned a link the first time you click on it. Then, the second time you click, it has a link assigned.

It’s not good practice to assign both a link and an onClick() routine - they can conflict.

The following might be better:

import wixLocation from 'wix-location';
$w.onReady(function () {});
export function button10_click(event, $w) {
    const email = $w('#dataset1').getCurrentItem().emailAddress;
    wixLocation.to('mailto:' + email);
}

See the wix-location.to() API for more information.

Good luck,

Yisrael

Thank you Yisrael, that works great and makes a lot of sense.

Hi @yisrael-wix please help me out, I am facing the same issue and here is my code to change slides when clicked on a button once but instead the users are facing issues and complaining that they have to click twice to change the slides:

export function button1_click ( event ) {
$w ( “#button1” ). onClick (()=> { $w ( “#slideshow1” ). changeSlide ( 0 )})
}

export function button3_click ( event ) {
$w ( “#button3” ). onClick (()=> { $w ( “#slideshow1” ). changeSlide ( 2 )})
}
export function button2_click ( event ) {
$w ( “#button2” ). onClick (()=> { $w ( “#slideshow1” ). changeSlide ( 1 )})
}
export function button7_click ( event ) {
$w ( “#button7” ). onClick (()=> { $w ( “#slideshow1” ). changeSlide ( 3 )})
}
export function button8_click ( event ) {
$w ( “#button8” ). onClick (()=> { $w ( “#slideshow1” ). changeSlide ( 4 )})
}
export function button9_click ( event ) {
$w ( “#button9” ). onClick (()=> { $w ( “#slideshow1” ). changeSlide ( 5 )})
}

You have what’s basically 2 onClick functions interlocking. Either move the

$w("#button9").onClick(()=> {$w("#slideshow1").changeSlide(5)}) 

parts into the onReady function. Or remove the

$w("#button9").onClick(()=> {  })

parts.