i use this code to hide a strip called “#finiture” if a field in the dataset is empty
But not works, why?
If i use a different field for example “Press” what change on the code?
thank you
i use this code to hide a strip called “#finiture” if a field in the dataset is empty
But not works, why?
If i use a different field for example “Press” what change on the code?
thank you
I think it does not work, because you are using a dynamic code-part for a non-dynamic dataset.
→ getCurrentItem does only work on dynamic datasets.
If i am not right with my statement and you have the Agility of using getCurentItem, then you could try this one…
First define…
let myValue = $w(‘#prodottiDataset’).gerCurrentItem().finiture
Then check in if-query…
If(myValue){ … continue here …}
Oh and i see you wrote Finiture with an Capital-letter, shouldn’t it be–> “finiture”?
Check your DATAFIELD-ID first.
And next time use a CODEBLOCK to show a CODE please, instead of using a pic. Thanks.
Ok i edited the code but not works
@russian-dima do you have any ideas? Thank you
import wixData from 'wix-data';
import wixLocation from 'wix-location';
let product;
$w.onReady(async function () {
product = await $w('#productPage').getProduct();
initProduct();
wixLocation.onChange(async (location) => {
product = await $w('#productPage').getProduct();
initProduct();
})
})
async function initProduct() {
await $w('#prodottiDataset').setFilter(wixData.filter().eq('storeProducts', product._id));
//This not workd
let finiture = $w('#prodottiDataset').getCurrentItem().finiture;
if (finiture)
{
$w('#finiture').expand();
}
else {
$w('#finiture').collapse();
}
let gallery = $w('#prodottiDataset').getCurrentItem().galleriaProdotto;
if (gallery)
{
$w('#stripDettagli').expand();
}
else {
$w('#stripDettagli').collapse();
}
}
This is The DB fields name.
This is the page: https://www.shop.madeinlando.it/product-page/gb911
Still unclear, if your code is located on a dynamic , or a non-dynamic page ?
What do we know already?
Further, when working with datasets, your datasets should always first be ready, before working with them.
$w.onReady(function() {
$w(DATASET).onReady(()=>{
// your code here....
});
});
If you are using a —> DYNAMIC page, where you only can show an item at once…
import wixData from 'wix-data';
import wixLocation from 'wix-location';
const DATASET = '#prodottiDataset'
const DATABASE = 'Prodotti'
const REFERENCE1 = 'Finiture'
const REFERENCE2 = 'galleriaProdotto'
const STRIP1 = '#finiture'
const STRIP2 = '#stripDettagli'
$w.onReady(async function () {
$w(DATASET).onReady(()=>{
//$w(DATASET).setFilter(wixData.filter().eq('storeProducts', product._id));
let finiture = $w(DATASET).getCurrentItem().finiture;
let gallery = $w(DATASET).getCurrentItem().galleriaProdotto;
if (finiture) {$w(STRIP1).expand();} else {$w(STRIP1).collapse();}
if (gallery) {$w(STRIP2).expand();} else {$w(STRIP2).collapse();}
});
});
If you entered your dynamic page and starts to switch items, your 2x STRIPS will appear or disappear, related to their values connected to the related DATASET.
@russian-dima thank you, i try your code and works for the gallery but not works for finiture , i try some test and the problem probably is because Finiture is Multi-Reference field from the table Finiture.
How in can check if there is some elements inside?
if(finiture)
return always false, why? there is some way to check it there is some values inside?
console.log(finiture)
log undifined.
I tried
if(finiture.getTotalCount())
but not works.
Thank you
Add this line into your CODE:
let currentItem = $w(DATASET).getCurrentItem(); console.log(currentItem);
Take a look into the structure of the given RESULTS in this console-log!
Open the given Data-Object → by clicking onto the 3-dots → {…}
Make a screenshot of the shown results.
@russian-dima there isn’t the field Finiture, why? Inside the dataset there is the field.
Object
Titolo1: "FUTURA FA903"
altDettagliTecnici: "Dimensioni vaso in ceramica artigianale, LANDO FA903, collezione Futura, Made in Italy"
altImmagineDettaglio1: "Dettaglio vaso in ceramica artigianale, LANDO FA903, collezione Futura, Made in Italy"
altImmagineDettaglio2: "Dettaglio vaso in ceramica artigianale grezzo e smaltato, LANDO FA903, collezione Futura, Made in Italy"
altImmaginePrincipale: "Vaso in ceramica LANDO FA903, collezione Futura, Made in Italy"
descrizione: "Con la collezione FUTURA Paola Navone reinventa le forme delle ceramiche di tradizione barocca e trasforma in eccezionali elementi di decorazione contemporanea gli oggetti delle botteghe artigiane del territorio di Bassano del Grappa e Nove, dal cui fascino la designer ha tratto ispirazione.\nSpogliati delle tradizionali smaltature colorate, gli oggetti della collezione si liberano dell'eccesso decorativo barocco e lasciano ora trionfare le forme e i volumi, accentuati dalla purezza della materia bianca. \nRichiamo a favole d'infanzia, alle atmosfere orientali delle Mille e una notte, la caffettiera FUTURA FA903 decora l'ambiente con i suoi tratti arabeschi.\nIl biscotto di ceramica modula i volumi, lo smalto incontra la sostanza porosa e ne modifica l'essenza, le linee vorticose si innalzano ad eseguire le sinfonie del manico ad ansa e del beccuccio. Il coperchio a cupola è sormontato da un pomello a coste, che ingentilisce la caffettiera in tutte le sue dimensioni."
descrizione1: "Lo smalto, necessario a rendere la materia impermeabile, lascia spazio nella colata, alla materia grezza del biscotto di ceramica. La smaltatura si adagia così nella parte interna, sul coperchio e su parte del manico, accentuando la matericità di questo oggetto d'arredo di design."
descrizione2: "Il merletto rende aggraziata la parte bassa della caffettiera della nonna e il collo alleggerisce le forme portandole verso l'alto, dove lo smalto bianco unisce il vaso al coperchio."
descrizioneDimensioni: "FA903: cm 32 x 30 x 50 h\nFA904: cm 28 x 25 x 40 h\nFA905: cm 23 x 20 x 32 h\nFA906: cm 16 x 15 x 23 h "
descrizioneEsterna: "Caffettiera"
dettaglioTec: "dettagli tecnici"
famiglia: {highlightsTesto: "<ul class=\"font_7\">\n <li><p class=\"font_7\">Design…ass=\"font_7\">Smaltati internamente</p></li>\n</ul>", jpgHighlights: "wix:image://v1/c1d14a_0e3ee6e285c24115ad59bb1c2cec…/FA900_098.tif#originWidth=2520&originHeight=1446", immagineFutura: "wix:image://v1/c1d14a_ac9b6b0358a742de9294cddf68e9…FA900_dett4.jpg#originWidth=1920&originHeight=600", _id: "e1538695-f0bd-4674-abe8-4a6bd952f5e3", _owner: "c1d14a36-005b-46a3-8738-263f76b14761", …}
galleriaProdotto: (3) [{…}, {…}, {…}]
immagineDettaglio1: "wix:image://v1/c1d14a_8677f078d3f5438fb60b8bb03d76dba6~mv2.png/fa903dett1.png#originWidth=1500&originHeight=1500"
immagineDettaglio2: "wix:image://v1/c1d14a_a0dbca2aa25c461fbf5074ae5804676d~mv2.png/fa903dett2.png#originWidth=1500&originHeight=1500"
immagineEsterna: "wix:image://v1/c1d14a_ff9157054b544ddfa40ed2543528a6ed~mv2.png/FA903_gruppo.png#originWidth=1500&originHeight=1500"
immaginePrincipale: "wix:image://v1/c1d14a_3531ca18388949e7bc0444810383659e~mv2.png/fa903.2.png#originWidth=1500&originHeight=1500"
lingua: "c2479e29-016c-49dd-9a2b-7cf690bd5f50"
link-ceramiche-title: "/c/futura-fa903-vaso-design-ceramica"
press: "Hanno parlato di FUTURA"
press1: (18) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
pressoGallery: "da 115€"
prodotto: "caa8b764-f9f4-c23e-12f3-a6c182054121"
sliderIniziale: (2) [{…}, {…}]
storeProducts: "caa8b764-f9f4-c23e-12f3-a6c182054121"
title: "FA903 IT"
titolo1: "la smaltatura"
titolo2: "anima barocca"
titoloDescrizione: "Lo sguardo si muove tra i volumi sinuosi barocchi"
vaso: "CAFFETTIERA IN CERAMICA BIANCA SMALTATA "
visibilit: true
_createdDate: Wed Jan 27 2021 15:06:20 GMT+0100 (Ora standard dell’Europa centrale) {}
_id: "7a101834-9f64-4867-886a-bc0ddef765f4"
_owner: "c1d14a36-005b-46a3-8738-263f76b14761"
_updatedDate: Wed Jun 23 2021 10:03:36 GMT+0200 (Ora legale dell’Europa centrale) {}
__proto__: Object
I try this code because there is an other dataset with Finiture called #finitureDataset
$w("#finitureDataset").onReady(()=>{
if ($w("#finitureDataset").getTotalCount()) {
$w("#stripFiniture").expand();
} else {
$w("#stripFiniture").collapse();
}
});
But not works, why?
If i log
console.log( $w("#finitureDataset").getCurrentItem());
Always is null, but there is 2 Finiture.
Did you —> SYNC → Preview-DB with Live-DB ?
@russian-dima sandbox is disable, so Live and preview DB is the same.
@work32491
Yes, i already suggested it looking onto the pics you showed. There wasn’t able to see either PREVIEW, NOR LIVE.
I would need to investigate your project, to recognize the failure. I can’t do it from here, since my knowledge about referenced-datafields has still boundaries.