Frustrated with Linkable Mixin..

Working with a dynamic page with a URL dataset field

OnReady is defining the link and target of a button:

let app = $w("#dynamicDataset").getCurrentItem().appLink;
 if (app === undefined || app === "undefined" || app === null || app === "") {
 console.log("app null");
 } else {
 $w('#viewAppButton').link = app;
 $w('#viewAppButton').target = "_blank";
 console.log("app");
 console.log($w('#viewAppButton').link);
 console.log($w('#viewAppButton').target);
 }

Button On Click is doing some analytics recording stuff but for purposes of this discussion let’s say it’s a console log

 console.log("clicked");

The button is simply not working… it’s incredibly frustrating. The OnReady logs are giving me all the right information, but the function is not happening.

Thoughts?

Maybe you didn’t set the click event correctly.

What is the variable app that you are setting the button’s link to? Is it a supported link type ?


Other types of links are not supported.

Have you put it inside dataset.onReady() ?

Thanks, I’ve had a look at the documentation, the link is a URL type and is a URL field in a database.

Here’s the pages code in onReady:

$w.onReady(function () {

 $w("#dynamicDataset").onReady(() => {
 console.log("Product data ready");

 checkContent();

 $w("#imgProduct").fitMode = "fixedWidth";

 console.log("pdf link = " + $w("#dynamicDataset").getCurrentItem().specProductPdf);
 console.log("app link = " + $w("#dynamicDataset").getCurrentItem().appLink);
 console.log("bim link = " + $w("#dynamicDataset").getCurrentItem().bimLink);

 let datasheet = $w("#dynamicDataset").getCurrentItem().specProductPdf;
 if (datasheet === undefined || datasheet === "undefined" || datasheet === null || datasheet === "") {
 console.log("datasheet null");
 } else {
 //  datasheet.toString();
 $w('#viewDatasheetButton').link = datasheet;
 $w('#viewDatasheetButton').target = "_blank";
 console.log("datasheet");
 console.log($w('#viewDatasheetButton').link);
 console.log($w('#viewDatasheetButton').target);
 }

 let app = $w("#dynamicDataset").getCurrentItem().appLink;
 if (app === undefined || app === "undefined" || app === null || app === "") {
 console.log("app null");
 } else {
 // app.toString();
 $w('#viewAppButton').link = app;
 $w('#viewAppButton').target = "_blank";
 console.log("app");
 console.log($w('#viewAppButton').link);
 console.log($w('#viewAppButton').target);
 }

 let bim = $w("#dynamicDataset").getCurrentItem().bimLink;
 if (bim === undefined || bim === "undefined" || bim === null || bim === "") {
 console.log("bim null");
 } else {
 //  bim.toString();
 $w('#viewBimFileButton').link = bim;
 $w('#viewBimFileButton').target = "_blank";
 console.log("bim");
 console.log($w('#viewBimFileButton').link);
 console.log($w('#viewBimFileButton').target);
 }
 });
});

And here’s the onClick:

export async function viewDatasheetButton_click(event) {

 let isAdminLocal = local.getItem("isAdmin");
 let isAdminSession = session.getItem("isAdmin");
 let isAdminMemory = memory.getItem("isAdmin");

 if (isAdminLocal === "true" || isAdminSession === "true" || isAdminMemory === "true") {

 console.log("*clicked*");

 console.log("************************************** admin activity - hidden from analytics - proceeding **************************************")
 wixLocation.to($w("#dynamicDataset").getCurrentItem().specProductPdf);

 } else {

 console.log("*clicked*");

 let userId = wixUsers.currentUser.id;

 let client = $w('#dynamicDataset').getCurrentItem().title;
 let focus = $w('#dynamicDataset').getCurrentItem().specProduct;
 let specificationEmailed = false;
 let datasheet = true;
 let product = $w("#dynamicDataset").getCurrentItem().specProduct;
 let bim = false;
 let app = false;
 let impression = false;
 let engagement = false;
 let click = false;
 let advert = false;
 let course = false;
 let sample = false;
 let search = false;
 let itemId = $w('#dynamicDataset').getCurrentItem()._id;
 let itemOwner = $w('#dynamicDataset').getCurrentItem()._owner;
 let permissionCode = $w('#dynamicDataset').getCurrentItem().collectionId;

 await submit(userId, client, focus, impression, engagement, click, advert, product, course, search, itemId, itemOwner, specificationEmailed, datasheet, bim, app, permissionCode, sample)
 .then((result) => {
 console.log("Success = " + result);
 wixLocation.to($w("#dynamicDataset").getCurrentItem().specProductPdf);
 })
 .catch((error) => {

 let errorLocation = event.target.id;

 let errorDetails = {
 "userInformation": {
 "email": $w('#txtTrackingUsrEmail').text,
 "name": $w('#txtTrackingUsrCurrent').text,
 "firstName": $w('#txtTrackingUsrFName').text,
 "lastName": $w('#txtTrackingUsrLName').text,
 "phone": $w('#txtTrackingUsrPhoneNumber').text,
 },
 "userLocation": {
 "trackingStatus": $w('#txtTrackingUsrStatus').text,
 "userLatitude": $w('#txtTrackingUsrLat').text,
 "userLongitude": $w('#txtTrackingUsrLon').text,
 "userContinent": $w('#txtTrackingUsrContinent').text,
 "userCountryCode": $w('#txtTrackingUsrCountryCode').text,
 "userCountry": $w('#txtTrackingUsrCountry').text,
 "userRegion": $w('#txtTrackingUsrRegion').text,
 "userCity": $w('#txtTrackingUsrCity').text,
 "userIpAddress": $w('#txtTrackingUsrIP').text,
 "userIpName": $w('#txtTrackingUsrIpName').text,
 "userIpType": $w('#txtTrackingUsrIpType').text,
 "userIsp": $w('#txtTrackingUsrIsp').text,
 "userFormFactor": $w('#txtTrackingUsrFormFactor').text,
 "userOrg": $w('#txtTrackingUsrOrg').text,
 },
 "pageLocation": {
 "baseUrl": wixLocation.baseUrl,
 "path": wixLocation.path,
 "prefix": wixLocation.prefix,
 "protocol": wixLocation.protocol,
 "query": wixLocation.query,
 "queryParams": wixLocation.queryParams,
 "url": wixLocation.url
 }
 }

 let errorMessage = error.message;
 let errorCode = error.code;
 errorLogging(errorMessage, errorCode, errorDetails, errorLocation)
 });

 $w('#analyticsProducts').setFieldValue("migratedToAnalytics", true);
 $w('#analyticsProducts').setFieldValue("manufacturerViewed", $w('#dynamicDataset').getCurrentItem().title);
 $w('#analyticsProducts').setFieldValue("productViewed", $w('#dynamicDataset').getCurrentItem().specProduct);
 $w('#analyticsProducts').setFieldValue("comment", "Viewed the datasheet link for " + $w('#dynamicDataset').getCurrentItem().specProduct + " by " + $w('#dynamicDataset').getCurrentItem().title + " to " + $w('#txtTrackingUsrCurrent').text + "using email: " + $w('#txtTrackingUsrEmail').text);
 $w('#analyticsProducts').setFieldValue("productOwner", $w('#dynamicDataset').getCurrentItem()._owner);
 $w('#analyticsProducts').setFieldValue("productId", $w('#dynamicDataset').getCurrentItem()._id);
 $w('#analyticsProducts').setFieldValue("collectionId", $w('#dynamicDataset').getCurrentItem().collectionId);

 // user details
 $w('#analyticsProducts').setFieldValue("email", $w('#txtTrackingUsrEmail').text);
 $w('#analyticsProducts').setFieldValue("fullName", $w('#txtTrackingUsrCurrent').text);
 $w('#analyticsProducts').setFieldValue("firstName", $w('#txtTrackingUsrFName').text);
 $w('#analyticsProducts').setFieldValue("lastName", $w('#txtTrackingUsrLName').text);
 $w('#analyticsProducts').setFieldValue("contactNo", $w('#txtTrackingUsrPhoneNumber').text);

 // user physical location
 $w('#analyticsProducts').setFieldValue("country", $w('#txtTrackingUsrCountry').text);
 $w('#analyticsProducts').setFieldValue("province", $w('#txtTrackingUsrRegion').text);
 $w('#analyticsProducts').setFieldValue("city", $w('#txtTrackingUsrCity').text);

 // data save
 $w("#analyticsProducts").save()
 .catch((error) => {
 let errorLocation = (event.target.id + " - " + error);

 let errorDetails = {
 "userInformation": {
 "email": $w('#txtTrackingUsrEmail').text,
 "name": $w('#txtTrackingUsrCurrent').text,
 "firstName": $w('#txtTrackingUsrFName').text,
 "lastName": $w('#txtTrackingUsrLName').text,
 "phone": $w('#txtTrackingUsrPhoneNumber').text,
 },
 "userLocation": {
 "trackingStatus": $w('#txtTrackingUsrStatus').text,
 "userLatitude": $w('#txtTrackingUsrLat').text,
 "userLongitude": $w('#txtTrackingUsrLon').text,
 "userContinent": $w('#txtTrackingUsrContinent').text,
 "userCountryCode": $w('#txtTrackingUsrCountryCode').text,
 "userCountry": $w('#txtTrackingUsrCountry').text,
 "userRegion": $w('#txtTrackingUsrRegion').text,
 "userCity": $w('#txtTrackingUsrCity').text,
 "userIpAddress": $w('#txtTrackingUsrIP').text,
 "userIpName": $w('#txtTrackingUsrIpName').text,
 "userIpType": $w('#txtTrackingUsrIpType').text,
 "userIsp": $w('#txtTrackingUsrIsp').text,
 "userFormFactor": $w('#txtTrackingUsrFormFactor').text,
 "userOrg": $w('#txtTrackingUsrOrg').text,
 },
 "pageLocation": {
 "baseUrl": wixLocation.baseUrl,
 "path": wixLocation.path,
 "prefix": wixLocation.prefix,
 "protocol": wixLocation.protocol,
 "query": wixLocation.query,
 "queryParams": wixLocation.queryParams,
 "url": wixLocation.url
 }
 }

 let errorMessage = error.message;
 let errorCode = error.code;
 errorLogging(errorMessage, errorCode, errorDetails, errorLocation)
 });
 }
}

page link: https://editor.wix.com/html/editor/web/renderer/edit/ab9e2d9a-adb7-4a5f-b604-12c2a9745474?metaSiteId=a804e724-2fc4-4d2b-ab68-d879299803bf&editorSessionId=37d6f4b0-c03e-4c00-8096-1e935d7337f3&referralInfo=dashboard

Hi JD, please see above

@spamushere Is the emailSpecificationButton_click toggled on the property panel?

@jonatandor35 Yes sir

Any idea?

I’ve add the following line due to the click not working. If I remove it, nothing happens:

 wixLocation.to($w("#dynamicDataset").getCurrentItem().specProductPdf);

@spamushere You can’t do it like that. You should convert the internal URI into a URL first (I don’t have the Wix editor it in front of me right now, so I can’t tell you the exact conversion formula).
But basically as far as I remember, you have to change it to something like:
https://wufdfdf.usrfiles.com/ugid/ertcggtyrawd/file.pdf
(I don’t remember the exact pattern by heart)
(You can find the actual URL, if you go to the media manager, and hover over the file > click the 3-dot button, so use some .split(“/”) to extract the file id and put it inside the URL pattern).

@jonatandor35 Thanks JD, but it’s not a file, it’s an external website URL link

@spamushere So I don’t know, you have lots of code here. Try to use console.log() to locate the problem.

@jonatandor35 I have done so, everything works except the buttons function. This is why I am frustrated, because it seems that it doesn’t actually work.

The code is quite simple really;

onReady, onDatasetReady:

Gets the link and logs it, sets the button link and target, working perfectly…

 let datasheet = $w("#dynamicDataset").getCurrentItem().specProductPdf;

 $w('#viewDatasheetButton').link = datasheet;
 $w('#viewDatasheetButton').target = "_blank";
 console.log("datasheet");
 console.log($w('#viewDatasheetButton').link);
 console.log($w('#viewDatasheetButton').target);

Then in the onClick function, which is set in the properties panel


 console.log("**clicked**");

 // Then some analytics stuff

But it should just work when clicked. I’ve also tried making this an

$w("#viewDatasheetButton").onClick((event)=>{

event in the onReady code, while still setting the target and link in the onReady and onDataset ready. Simply not working and highly frustrating. maybe @Yisrael (Wix) knows better?