Typeerror - OnClick is not a function

Hello there!
I was exploring WixCode example on Recipe/Review and kind of adopting it to my website.

Of particular interest was the ‘Add a Review’ Light box where a user can post a review on a recipe or a product etc…

But, every time I try to ‘Add review’ in the Preview mode I’m getting a ‘Typeerror’ on the console. It says ‘TypeError: $w(…).onClick is not a function’ . (See below)

I’m guessing this refers to following lines in the code as it doesn’t allow me to select a star.
$w.onReady(function () {
// set star events and init the stars
for (let i=0; i < 5; i++) {
$w(starsId[i]).onClick(starClick(i));
$w(starsActiveId[i]).onClick(starClick(i));
$w(starsId[i]).onMouseIn(starHover(i));
$w(starsActiveId[i]).onMouseIn(starHover(i));
}
showSelectedStars();

$w("#reviewsDataset").onBeforeSave(reviewsBeforeSave); 
$w("#reviewsDataset").onAfterSave(reviewsAfterSave); 

});

What is weird is that it was working perfectly fine last night, it only started showing this error this morning.

Is there a fix? Thanks very much in advance!

The full ‘Page code’ for the lightbox is pasted below:
import {lightbox} from “wix-window”;

const starsId = [‘#starGray1’, ‘#starGray2’, ‘#starGray3’, ‘#starGray4’, ‘#starGray5’];
const starsActiveId = [‘#starBlue1’, ‘#starBlue2’, ‘#starBlue3’, ‘#starBlue4’, ‘#starBlue5’];

let selectedStar = 0;

$w.onReady(function () {
// set star events and init the stars
for (let i=0; i < 5; i++) {
$w(starsId[i]).onClick(starClick(i));
$w(starsActiveId[i]).onClick(starClick(i));
$w(starsId[i]).onMouseIn(starHover(i));
$w(starsActiveId[i]).onMouseIn(starHover(i));
}
showSelectedStars();

$w("#reviewsDataset").onBeforeSave(reviewsBeforeSave); 
$w("#reviewsDataset").onAfterSave(reviewsAfterSave); 

});

function starClick(index) {
return function(event) {
selectedStar = index+1;
checkEnablePostButton();
showSelectedStars();
};
}

function showSelectedStars() {
showStars(selectedStar);
}

function showStars(numberOfStars) {
for (let i=0; i < 5; i++) {
if (i < numberOfStars)
$w(starsActiveId[i]).show();
else
$w(starsActiveId[i]).hide();
}
}

function starHover(index) {
return function(event) {
showStars(index+1);
};
}

function clearStarHover() {
showSelectedStars();
}

function reviewsBeforeSave() {
$w(“#reviewsDataset”).setFieldValue(‘rating’, selectedStar);
let reviewId = lightbox.getContext().id;
$w(“#reviewsDataset”).setFieldValue(‘recipeId’, reviewId);
}

function reviewsAfterSave() {
lightbox.close();
}

function checkEnablePostButton() {
let item = $w(“#reviewsDataset”).getCurrentItem();
if (selectedStar > 0 && !!item.name && !!item.review)
$w(‘#postButton’).enable();
else
$w(‘#postButton’).disable();
}

export function closeButton_onClick(event) {
lightbox.close();
}

export function clearStarsHoverHotspot_onMouseIn(event) {
clearStarHover();
}

export function reviewsDataset_onItemValuesChanged(event) {
checkEnablePostButton();
}

Hi, thanks for reporting the issue! We’re looking into it.

Thanks Tomer!! Looking forward to hearing back…

We identified the issue and we are working on a fix. Thanks!

I have adopted the same code into my website. So if there is any change that we are supposed to make to get it to work, please do share it here… Thank you!

Hey, the fix was deployed, the example and the relative code now works.

EDIT: just to be clear, you don’t have to do anything, your code will work :slight_smile:

Hey Tomer,
Thank a lot! The code is working now!

I had this exact same problem.

I implemented this tutorial :

and I’m getting the following error:
TypeError: $w(…).onAfterSave is not a function

I’m dealing with a similar issue but I’m using the Wix Gift Quiz example https://www.wix.com/code/home/example/Gift-Quiz

I keep getting the exact same error message
‘TypeError: $w(…).onClick is not a function’
I even used the template provided by Wix which seems to work fine as is but as soon as I make any changes the error message pops up.

There was never a solution listed here since it was a change that was deployed on the back end. Any ideas?

Is the onClick issue really resolved? Surprised to see same issue even today at 2019 June.

I have the same problem. Does anyone have any ideas? I really need an answer.

It probably means that you added the onClick() to a non-existing element. Check the property id.

any solutions bros? i originally was a back end problem :frowning:

Hello, I also started getting errors from all of my functions as below;

TypeError: $w(…).maximize is not a function

This is an old post from 2018 and is being closed, therefore please add a new post if you need more help with a refer link back to this thread if needed.

As for your issue, make sure that the element that you are using for this does actually support maximize.

Like the Wix Chatbox which supports maximize.
https://www.wix.com/corvid/reference/$w.Chatbox.html#maximize

$w("#myChatbox").maximize();