Hi,
I have added a ratings input and display to my website following this tutorial… https://support.wix.com/en/article/wix-code-tutorial-capturing-and-displaying-ratings
It works fine as as long as there is a value already in the database for the total ratings value and the total number of ratings but if these values are null then there is an error and the database does not get updated.
When we launch the site, I would like to start with ‘no ratings’ and therefore the field values need to be null. How do I get around this?
Thanks,
Rachel
You should check if the value is null or undefined and then force the display to show no results. You can refer to these two examples:
Ratings Input and Display
Let visitors rate recipes and display the rating results.
Ratings by User
Let logged-in users rate recipes and edit their ratings.
Thanks Yisrael but I’m user the ratings display settings as per the tutorial so it is already set up to display no results if the field is null. The problem is getting the first rating, I’m sure this is an oversight in the tutorial as it does not explain how to counteract this.
@rachelskuse I was referring to the examples since I handle the “empty” case there. Options:
@yisrael-wix Ah, ok. I was receiving an error stating that “The value of rating parameter that is passed to the rating method cannot be set to the value “0”. It must be between 1 and 5” but it appears to still update ok so I’ll run with that. THANKS!
@rachelskuse aha - I understand a bit better now. Glad it’s working.
What you can do is check if the value is 0 (or null or undefined), and then just skip setting the rating value. This way you won’t get the warning about trying to set to “0”.
But then again, “if it works, don’t fix it”.
@yisrael-wix That’s my thinking! It always just bothers me when I see an error message!
@rachelskuse That’s the right way to think. It’s best to get rid of error message when possible.