Hi there,
I have added some code to my site and it seems like the code is right but I keep getting the “Parsing Error: Unexpected Token {” message. Please could someone assist? Here is my code:
Kind regards
Lenzo
Hi there,
I have added some code to my site and it seems like the code is right but I keep getting the “Parsing Error: Unexpected Token {” message. Please could someone assist? Here is my code:
Kind regards
Lenzo
Hi Lenzo!
Please share a link to your site or the full code you use on that page so one of us, the WixCode team, can inspect it and provide you with a solution.
Doron.
Hi there Doron,
That’s the only code I’m running thus far. Here is the link to the site: https://officiallenzo.wixsite.com/rivoltare
I look forward to your response.
Just In case you want to see the full code in text:
import wixUsers from ‘wix-users’;
$w.onReady( function () {
//TODO: write your page related code here…
$w("#button9").hide();
});
let user = wixUsers.currentUser;
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”
let isLoggedIn = user.loggedIn; // true
if (!isLoggedIn) { wixLocation.to(“/login”); }
let userRole;
let userEmail;
user.getEmail()
.then((email) => {
userEmail = email;
user.getRoles()
.then((roles) => {
userRole = roles[0].name;
// After the roles have been defined check them!
if (user.role === “Free Membership” && (isLoggedIn = user.loggedIn)
{
$w("#button9").show();
} **else** { $w("#button9").hide(); }
Hi Lenzo!
Your code was missing some parenthesis and brackets.
Also, the command of importing the WixLocation API was missing.
Your code should look something like that:
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#button9").hide();
});
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;
if (!isLoggedIn) {
wixLocation.to("/login");
}
let userRole;
let userEmail;
user.getEmail()
.then((email) => {
userEmail = email;
user.getRoles()
.then((roles) => {
userRole = roles[0].name;
if (user.role === "Free Membership" && (isLoggedIn = user.loggedIn)) {
$w("#button9").show();
} else {
$w("#button9").hide();
}
})
})
Let me know if its working for you.
I hope it helps!
Doron.
This restores the login condition and that is now working again. Thank you! I have noticed however that my user.role is undefined. I was under the impression that the user role changes if the user has bought a paid plan. I have a plan on my site called “Free Membership” and I’ve signed in as the user that has the free membership but the #button9 isn’t being displayed. Is there something I’m missing?
I double check and it seems as though paid plans don’t create a role when a user purchases them but reserve the role name anyway which means you can’t create a role that has the same name as your paid plan but you can’t refer to the already reserved role name of the paid plan either.
Is there perhaps a way to reference the users plan instead of their role?
Has anyone seen this color pattern before the color appears to operational or is the code just completely wrong I am trying to change the property id content from 1 page name to a new page name it was a duplicate copy of one to another but I need to align the property ID to the second page name they do not conflict in the site
If it’s supposed to be an arrow function that returns an object, you should wrap it further with parentheses.
data: () => ({
date: null,
// ...
});
Otherwise JS will try to interpret it as a function block.
I managed to remove the unexpected token placing another set of parenthese but the code did still not change the ID content
Can you send me a code file?
Parsing Error: Unexpected Token
have added some code to my site and it seems like the code is right but I keep getting the “Parsing Error: Unexpected Token {” message. Please could someone assist? Here is my code:
here is my code
import {createToken, encodeCard} from “public/stripeAPI.js”;
import {charge} from ‘backend/stripeProxy’;
var payment;
export function payNow(event) {
createToken(encodeCard(createCard()))
.then((token) => {
console.log("Card token: " + token);
charge(token, payment)
.then((chargeResponse) => {
console.log("Charge ID: " + chargeResponse.id);
});
});
}
export function pay_click(event) {
payNow();
}
export function amount_change(event) {
changeSate();
}
function changeSate() {
let payment = {
“amount”: ($w(“#amount”).value * 100),
“currency”: “USD”,
}
function createCard() {
return {
“name”: $w(“#cardholder”).value,
“number”: $w(“#cardnum”).value,
“cvc”: $w(“#cvc”).value,
“exp_year”: $w(“#year”).value,
“exp_month”: $w(“#month”).value
};
Hello! I am also encountering an unexpected token error.
My goal is to try and collapse a video player when a URL does not exist in the database field. I also want to hide text (a header) when the text field is empty in the database. This is for multiple text sections.
When I use the collapse video function alone, it works fine. However, when I combine it with the hiding functions for the text, it does not work.
Does anyone have any suggestions?
Thank you for your help!
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
var item = $w(“#dynamicDataset”).getCurrentItem(“#videoYouTube”);
if (!item.video) {$w(“#videoPlayer1”).collapse();}
});
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
var item = $w(“#dynamicDataset”).getCurrentItem();
if (item[“#CareerHighlights”] === null ) $w(“#text21”).hide();
else $w(“#text21”).show() ;
});
});
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
var item = $w(“#dynamicDataset”).getCurrentItem();
if (item[“#Testimonials”] === null ) $w(“#text23”).hide();
else $w(“#text23”).show() ;
});
});
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
var item = $w(“#dynamicDataset”).getCurrentItem();
if (item[“#SetUp”] === null ) $w(“#text25”).hide();
else $w(“#text25”).show() ;
});
});
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
var item = $w(“#dynamicDataset”).getCurrentItem();
if (item[“#Introduction”] === null ) $w(“#text28”).hide();
else $w(“#text28”).show() ;
});
});
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
var item = $w(“#dynamicDataset”).getCurrentItem();
if (item[“#Pricing”] === null ) $w(“#text30”).hide();
else $w(“#text30”).show() ;
});
});
Hello, I have a similar problem. Parsing error with onReady function - I think I’m close!
SITUATION: I am trying to filter a data collection by the login user’s email address. As Admin I have added the initial records to the collection and need the ability for my members to update their address information as needed.
More than half of our members may not edit their information nor go online at all but I need everyone’s info for our roster (which is displayed in a repeater on a page visible to Members). Many of our members are elderly and are not computer savvy.
As admin, I add the initial record when I approve the member at registration
Here is the code I am using to fill an input field with the logged in user’s email address and then trying to use that to filter the data collection which is Read/Write so they can then edit it (on a Member page). I have a parsing error and can’t figure out what token is missing to make the code work. I hope someone can take a quick look to help.
import wixUsers from ‘wix-users’;
import wixData from “wix-data”;
$w.onReady( function ()
{ $w(“#dataset5”).onReady( () => { //DocentRoster data set
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;
let userRole = user.role; user.getEmail() .then( (email) => {
let userEmail = email;
$w(‘#input40’).value = userEmail; $w(“#dataset5”).setFieldValue(“loginEmail”,$w(‘#input40’).value);
let filter = $w(“#input40”).value; $w(“#dataset5”).setFilter(wixData.filter().contains(“docentEmail”, filter));
wixData.query(“DocentRoster”)
.contains(“docentEmail”,$w(“#input40”).value)
.find()
.then(res => { $w(‘#box35’).expand();
Box35 has the fields I want the user to be able to edit (address, phone, comments, preferences, etc.). All are from the DocentRoster set up as Read/Write with no filter.
Thanks in advance if anyone can spot what’s I’ve done wrong.
This post is from 2018 and is being closed.
Please add your own issue into a new post instead of bumping up an old post.
Also, add any code in a code block as stated in the Forum Guidelines.
You might want to look at something like a Member Profile as in this tutorial here.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area