I have a dataset (site content permissions) named contractors list. I have a page (contractor List) that display all content in this dataset name and done by repeater. On this repeater I have a button that show if contractor is active and name active. In the dataset I have ActiveStatus element that is Boolean based on true or false. so when activeStatus is true than active button is displayed otherwise is hidde. this is my code
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
$w . onReady (() => {
let status = $w ( “#repeater3” ). getCurrentItem ( ‘activeStatus’ );
if ( status === true ) {
$w ( ‘#active’ ). show ();
} else {
$w ( ‘#active’ ). hide ();
}
});
what am i doing wrong here
As already mentioned before (i do not understand why you delete your post and reopen it again, while you already got some answers?), you are missing the dataset-onReady-part.
Your dataset has first to be ready to work well!
https://www.wix.com/velo/reference/wix-dataset/dataset/onready
My apologies i am under the weather. please see the code below
$w . onReady (() => {
$w ( “#ContractorsList” ). onReady ( () => {
$w ( “#ContractorsList” ). refresh ()
. then ( () => {
console . log ( “Done refreshing the dataset” );
});
});
let status = $w ( “#repeater3” ). getCurrentItem ( ‘activeStatus’ );
if ( status === true ) {
$w ( ‘#active’ ). show ();
}
else {
$w ( ‘#active’ ). hide ();
}
});
with all this it still tell me An element with the ID ‘#ContractorsList’ does not exist on this page. Select another element and view or edit its ID in the Properties & Events panel.
and contractorlists is my dataset
Check the right ID of your —> DATASET!
-click onto the → DATASET-ICON <—
-take a look into the → PROPERTIES-PANEL <—
-there you will find an → ID ← beginning with —> #
Thank you for your help the code now is right
$w . onReady (() => {
$w ( “#dataset1” ). onReady ( () => {
$w ( “#dataset1” ). refresh ()
. then ( () => {
console . log ( “Done refreshing the dataset” );
});
});
let status = $w ( “#dataset1” ). getCurrentItem (). activeStatus ;
if ( status === true ) {
$w ( ‘#active’ ). show ();
}
else {
$w ( ‘#active’ ). hide ();
}
});
however it still doe snot work. what am i missing here
You are missing a → “DYNAMIC-DATASET”–> since your DATASET is → NON-DYNAMIC.
. getCurrentItem () → works only on → DYNAMIC-DATASETS!
so what work on a non dynamic set
Awsome
function getItems (fromIndex: number, numberOfItems: number):Promise
now how do i found
fromindex,
number,
number ofitems
number
if you do not mind explain it to me
You wrote, that you use a —> REPEATER.
When using a REPEATER which is also connected by the DATASET, you don’t need to code trough-dataset anymore. Then you can do it directly trough → REPEATER.
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(()=> {
$w("#repeater3").onItemReady(($item, itemData, index)=>{
if (itemData.activeStatus===true) {$w('#active').show();}
else {$w('#active').hide();}
});
});
ok but i do not want it on click. when a member open this page he will quickly see if this contractor is active or not. he does need to click on it
ok you stated to use this code
$w . onReady (()=>{ $w ( “#repeater3” ).onItemReady(($item, itemData, index)=>{ if (itemData. activeStatus ===true ){ $w ( ‘#active’ ). show ();} else { $w ( ‘#active’ ). hide ();}});});
in the database i have field name ActiveStatus and filedkey activeStatus
what is $item
what is Itemdata
how can i find it is index
please advise
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(()=> {
$w("#repeater3").onItemReady(($item, itemData, index)=>{
console.log(itemData._id)
console.log(itemData.title)
console.log(itemData.activeStatus)
if (itemData.activeStatus===true) {$w('#active').show();}
else {$w('#active').hide();}
});
});
Take a look into —> CONSOLE !
Do you know, what is the CONSOLE ?
If not → open your GOOGLE-CHROME-BROWSER.
Press —> F-12
And navigate to —> CONSOLE
-run your code and take a look which RESULTS are logged in the CONSOLE?
well i see one issue that my active button is not connected to dataset. Also i am not able to connected
You perhaps should first learn some coding-basics, before starting a more complex project.
Learn how to use the → CONSOLE. Find out which advantages it gives you, when using the console.
Study → COLLECTIONS, DATASETS & REPEATERS
Also take a look onto the given VELO-API.
All this will help you to understand what you are doing.
ok so i went ahead and created a blank button and a text that display active or inactive based on the dataset. I went ahead and removed boolean and assign text to it
i am in process in learning however I did not expect if statement to be this complicated, my appologies
It will get more and more → complicated. You have just started.
The more code on your site → the more complex it will get → the more difficult it will be to understand → the more QUESTIONS you will have.
This is a normal coding-history, when working on a project.
Best METHOD how to work???
→ Do everything step by step! Do not start new coding lines, till the already written ones do not work properly.
Use ALWAYS → console-logs → they will help you a lot.