Hello,
This seems very basic, but for some reason I can’t get it to work. I want the Onclick for button 60 to be called only if the if statement is valid (input10 has text).
I have tried many ways, and I simply can’t get it to work. However, the onclick event happens without the if statement.
($w(’ # input10’).value.length >= 8)
($w(’ #input 10’).value !== “”)
($w(’ #input 10’).value === true)
here is the code block that doesn’t seem to work :
if
($w('#input10').value.length >= 8)
{
$w('#button60').onClick((event) => {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
if (!isLoggedIn) {
wixUsers.promptLogin().then(() => {
processPlan(planId, planPrice);
})
} else {
processPlan(planId, planPrice);
}
}
);
}
The code for the entire page:
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixPay from 'wix-pay';
import wixPaidPlans from 'wix-paid-plans';
import wixUsers from 'wix-users';
$w.onReady(function () {
const currentPlanObject = $w("#dynamicDataset").getCurrentItem();
const planId = currentPlanObject._id;
const planPrice = currentPlanObject.price;
if
($w('#input10').value.length >= 8)
{
$w('#button60').onClick((event) => {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
if (!isLoggedIn) {
wixUsers.promptLogin().then(() => {
processPlan(planId, planPrice);
})
} else {
processPlan(planId, planPrice);
}
}
);
}
});
function processPlan(myId) {
wixPaidPlans.purchasePlan(myId).then(orderObject => {
wixWindow.openLightbox("Contact1", orderObject)
.then((goForIt) => {
if (goForIt) {
wixPay.startPayment(orderObject.wixPayOrderId);
}
});
})
}
Please help! I hope it’s just some small mistake I made.
Thanks in advance!