I have tried for days now to make this work but still fail so please have a look at this code. expiryDate1 is the name of the field and it isn´t empty but image89 is not collapsing and image77 is not expanding. With other words; the lamp is “off” and dark but shall be flashing (image77 is a gif).
Just an example… (in this case the → _createdDate ← FIELD was used).
import wixData from 'wix-data';
$w.onReady(()=>{
//wixData.get("Members", wixUsers.currentUser.id);
//const date = $w("#dataset5").getCurrentItem().expiryDate1;
wixData.query("DATABASE")
.isNotEmpty('_createdDate')
.find()
.then((results)=> {
if(results.items.length < 0) {console.log("no renting time");}
else {console.log("Data found!!!");
console.log(results.items);
let date = results.items[0]._createdDate
console.log(date);
date = results.items[0]._createdDate.toLocaleDateString()
console.log(date);
//$w("#text424").text = date.toLocaleDateString()
//$w("#image89").collapse();
//$w('#image77').expand();
}
});
});
Use a repeater for results and create your —> “LAMP-FUNCTION” which will show two different states of the lamp → (IF-ELSE-STATEMENT) inside the RESULTS.
Thank you very much Velo-Ninja! I didn´t notice until now that you actually had added this example in my thread. About your repeater-tip, do you mean that the lamp-elements (images) also shall be included on this repeater or only the text? Another question is if the repeater shall be named to _createdDate?
Of course you can include the lamps into repeater.
A lamp has 2-states only (on & off) —> true & false → BOOLEAN-VALUE.
So, what you will need inside your database is…???
Exactly…!
a) either a BOOLEAN-FIELD
b) or another compareable field (for example STRING) + if-else-condition, to be able to create your wished function.
Connect it with your repeater, either by dataset or by code (code = better way).
Another question is if the repeater shall be named to _createdDate?
NO!!! Just call your repeater → like “rep1” ← my prefered name-syntax for repeaters, or “repeater1”, or however you want.
Why you want to give your repeater the ID —> _createdDate ???
—> _createdDate <— this is just an including DB-FIELD in every of your created DATABASES in WIX.
Sorry for my stupid questions but sometimes it is better to not include the images on the repeater because they are not always needed to be repeated but just collapsed or expanded (like in this case I thougth) and I have earlier seen codes with the name of the repeater so thats why I asked. My problem with using the regular field “createdDate” is that the system shows startdates for all my videos even when nobody are renting them. My and also your idea was that the flashing lamp shall be expanded when there are someone renting the video, else the dark lamp shall stay expanded. BUT now the createdDate field is never empty so that idea does not work as intended. Another thing I don´t understand is why the flashing lamp does not expand (and the dark lamp collapse) even when every field cell is showing an active renting time? This is really advanced and hard stuff for me because I don´t even know how I should create the database in a correct way.
I have 12 videos and have written them in this way with the nicknames of members that are currently renting the video and the expiry date for there personal renting time of this video:
Video 1 <---- title name Expiry date 1 Video 2 Expiry date 2
… … … …
The Joker (member nick) 2023-01-30
Artist (member nick) 2023-03-05
Marlboro (member nick) 2023-02-17 Marlboro 2023-03-10
The Clown (member nick) 2023-02-19 The Clown 2023-02-28
Rugbyman (member nick) 2023-03-08
Even one of your experienced colleagues thought this is a complicated thing to solve and it will probably take time for the computer to find the current members data among many tousands of members (if I succede with my site). On the other hand it should be pretty easy I think to make the lamps shift with each others if the system could regognize that the date field is filled or empty. But for some frustrating reason the flashing lamp is never seen Nothing works whatever I try so now I am close to giving up.
Do you think that Stackoverflow would be a good thing to use in this case? I belive it is but my code-knowledge is defeniately to low to be able to combine it with the lamp-function:
Instead of using —> nicknames —> maybe you can use the → OWNER-ID → " _owner "
All you need are two dates, right? → STARTING-DATE and EXPIRE-DATE to be able to calculate between these 2 dates. You also can break down date and time to a unique unit called → TIMESTAMP <— and with these timestamps you can calculate very easy.
You can make your first steps with MOMENT.JS starting with this example here…
I just played around a little bit and already after 5-10min of brainstorming got this results using MOMENT.JS…
I do not really know a lot about MOMENT, but seems to be easy to use, if it comes to DATES and TIMES.
import moment from 'moment';
$w.onReady(()=> {let mom = moment(); console.log(mom);
console.log("-----------------------");
console.log("YEAR: ", mom.year());
console.log("MONTH: ", mom.month());
console.log("WEEK: ", mom.week());
console.log("DAY: ", mom.day() + " / ---> " + "0=Sun,1=Mon,...,6=Sat");
console.log("HOUR: ", mom.hours());
console.log("MIN: ", mom.minutes());
console.log("SEC: ", mom.seconds());let tStamp = mom.unix();
console.log("T-STAMP :", tStamp);
console.log("-----------------------");
console.log('Which QUARTER of this year do we have?');
console.log("QUARTER: ", mom.quarter());
console.log("-----------------------");});
Follow the good explained VIDEOS provided in the link above and start your coding adventure.
Maybe you will also find some other posts about of how to work with dates and times…
[SOLVED] Find the difference (in hours), between 2 dates | Velo by WixHi All, I have previously used WIX to build great websites but am progressing to the point that I need to begin using WIX code. My first project is to build a form and backend database to capture user input. Is there a way that employees can fill in start and end dates in the form and then the l
There are a lot of examples out there.
On the other hand it should be pretty easy I think to make the lamps shift with each others if the system could regognize that the date field is filled or empty.
To determine if a BD-FIELD is not empty → .isNotEmpty(‘DB_FIELD_IDhere’)
To determine if a DB-FIELD is empty -------> .isEmpty(‘DB_FIELD_IDhere’)
Surely you have also generated a CODE for your REPEATER, after you have gotten the results of your query!?! Something like…
//---REPLACE THIS PART WITH YOUR REAL QUERY-CODE.....let res = your RESULTSlet items = res.items; console.log(items);$w('#yourRepeaterIDhere').data = items;//---REPLACE THIS PART WITH YOUR REAL QUERY-CODE.....
$w.onReady(()=>{console.log("Page is ready...)$w('#yourRepeaterIDhere').onItemReady(($i,iData,inx)=>{
console.log('index: ', inx);
console.log('item: ', iData);//LAMP-CHECK................//Generating some variables holding the needed date&time. let tStamp1 = iData._createdDate -> convert 2 timestamp
let tStamp2 = iData.expiryDate -> convert 2 timestamp
let tStamp3 = new Date();//NOW YOU SHOULD HAVE TWO or more different TIMESTAMPS// WHAT TO DO NEXT WITH THIS TIMESTAMPS???
a) CALCULATE ? --> tStamp1-tStamp2?
b) COMPARE? if(tStamp1===tStamp2) {...} else {...} ???//GENERATE YOUR IF_ELSE_CONDITIONif(iData.) {}else {}CONSOLE-LOG YOUR RESULT AND CHECK IT.
console.log(..........)});});
This is just a PROTOTYPE-EXAMPLE-SNIPET.
Put all things together, take your time, understand first what you are trying to do.
Take some days to practise to work with dates and times and their calculations.
At the end you will solve your problem, i am sure.
Thank you very much and I will do my best to learn and solve it. I have a full time job and other activities but my website can be a life-changer so it is still prioritized.
I will also try with using a multi-state-box for the lamps
Bad SYNTAX.
Everytime you open a —>( ) <— you also have to close it.
Everytime you open a —>[ ]<— you also have to close it.
Everytime you open a —>{ } <— you also have to close it.
So how do I close it? I have not found any information about that. Shall I for example write this: if ( value === “false” ) {} instead of this: if ( value === “false” ) { or how do you mean?
Yes I understand that there shall be a brace in the opposite direction but I don´t get where I shall place it? Shall it be directly beside the first one in this way: { } or shall it be placed in the end of the code snippet, like this } Can you please show me how you would write my code so that it does not give any red markings?
Yes it is more clear to write in that way but that doesn´t answer my main questions:
Where in the code shall I place the closure brace?
Why have you written } ) ; as closure brace if the open brace is { ? Shouldn´t it be just } ? I have googled for a tutorial about bracers but have not find a single page so how shall beginners understand what to close with and where in the code?? Is that something we are supposed to guess or calculate like mathematicians?
I have never understood why many guys write closure bracers like this or even more complicated “signs”? Shall I gater them all in the end for every open brace earlier in the snippet? I may be stupid but this is really not easy without an explanation and that is nowhere to be find: