@volkaertskristof Hi, I found out that the issue is when I change the field key from text (string) to number or date. I just tested the number value (name: share), but the result is the same like with the date field key.
@jankucera
I tried it out myself very fast,
It seems to work for me.
import wixData from 'wix-data';
$w.onReady(function () {
uniqueDropDown1();
});
//------------------------------------------------------SELECT DATE---------------
function uniqueDropDown1 (){
wixData.query("Bestellingen") // filter all old Dates out
.limit(1000)
.find()
.then(results => {
console.log(results)
const uniqueTitles = getUniqueTitles(results.items);
$w("#dropdown1").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item._createdDate);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr.toString(), value:curr.toString()};
});
}
}
@volkaertskristof Hi Kristof, thank very much! You are right! It works. One more question. Does it possible to format the date with some short form: Feb 17 2021. Any advice?
Atm my computer is off, there are ways, if you look it up a bit you wil find it.
You probably have to do something with curr(mm,dd,yyyy).toString()
@volkaertskristof thank you very much Kristof !
No problem, i’m happy it seems to work ![]()
Sorrybit took so long to replyz kinda forgot about it ![]()
Kind regards,
Kristof.
@volkaertskristof Hi Kristof, I need help with format the date. I’m still not successful with the final format date in the code. Can you help me to format the date in dropdown menu DD/MM/YYYY ? Thank you for any hep and guidance… Jan
@jankucera See the article Velo: Formatting Dates . For more specialized formatting, you can do an Internet search and come up with, well, millions of results.
@Yisrael (Wix) Hi, this method doesn't work..
$w.onReady(function () {
const date = $w("#dataset2").getCurrentItem()._createdDate;
$w("#date").text = date.toLocaleDateString()
console.log (date)
});
@jankucera You don’t say what doesn’t work - but one thing you should be aware of is to make sure that the dataset is ready when you try to access it. You should use the dataset onReady() function.
This should work:
let dateStr = date.toLocaleDateString('en-GB'));
@yisrael-wix ok, dataset onReady() function works…,but now I’d like to ask you for help, how to get in dropdown menu…
import wixData from ‘wix-data’ ;
$w.onReady( function () {
uniqueDropDown();
$w( “#dataset2” ).onReady( () => {
const date = $w( “#dataset2” ).getCurrentItem()._createdDate;
const options = {
day: “numeric” ,
month: “short” ,
year: “numeric” ,
}
$w( “#date” ).text = date.toLocaleDateString( “en-US” , options);
console.log (options)
})
})
//------------------------------------------------------SELECT DATE FROM DROPDOWN---------------
function uniqueDropDown (){
wixData.query( "All_Votes" ) // filter all old Dates out
.limit( 1000 )
.find()
.then(results => {
console.log(results)
const uniqueDate = getUniqueDate(results.items);
$w( “#dropdown1” ).options = buildOptions(uniqueDate);
});
function getUniqueDate(items) {
const titlesOnly = items.map(item => item._createdDate);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr.toString(), value:curr.toString()};
});
}
}
@jankucera
When you try this
$w("#dataset2").onReady( () => {
const date = $w("#dataset2").getCurrentItem()._createdDate;
const options = {
day: "numeric",
month: "short",
year: "numeric",
}
$w("#date").text = date.toLocaleDateString("en-US", options);
console.log (options)
})
Does the $w(“#date”).text shows the right format?
Ifso,
Add
const options = {
day: "numeric",
month: "short",
year: "numeric",
}
somewhere so its not in the onReady function.
Then for this:
return {label:curr.toString(), value:curr.toString()};
do:
return {label:curr.toLocaleDateString("en-US", options), value:curr.toString() };
I only changed the label, the label is the visible part.
the value is what you get when you need to search.
So if you also change the value it could stop working when searching/filtering.
Kind regards,
Kristof.
@volkaertskristof Hi Kristof, thank you, it works well!, here is the result:
//--------------------------------------SELECT DATE FROM DROPDOWN MENU---------------
function uniqueDropDown (){
wixData.query( "All_Votes" ) // filter all old Dates out
.limit( 1000 )
.find()
.then(results => {
console.log(results)
const uniqueDate = getUniqueDate(results.items);
$w( “#dropdown1” ).options = buildOptions(uniqueDate);
});
function getUniqueDate(items) {
const titlesOnly = items.map(item => item._createdDate);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
const options = {
day: “numeric” ,
month: “short” ,
year: “numeric” ,
}
return uniqueList.map(curr => {
return {label:curr.toLocaleDateString( “en-US” , options), value:curr.toString() };
});
}
}
one more question. How we can select from dropdown menu only one date instead of every raw record. I meant it to show in dropdown menu only one line: Feb 22, 2021? Any advice to that?
here is what I you can see in the dropdown menu
Oke so this is a more tricky part.
I’ll try to respond in an hour or 2.
I’m not at my computer atm.
But what you can do is make a function
Function returnLabel(label){
//Add the const option here
Return label.tolocaldatrstring(…)
}
Use this function in the query
And use a loop
Var newResult
For each item in result.items{
NewResult.push(returnLabel(result.items[itemnumber]._createdDate
}
Then use the getUniqueDate with the newResult
Hope i can get back to you with a better explained answer if i find the time today ![]()
Kind regards,
Kristof
Hi Kristof, fully understand and I very appreciate your help! Thank you.
What I don’t understand what is exactly process flow to create a label list based on unique date.
So it works?
The process to make a unique list with dates is that when you extract the data from the database you get an array. With dates you have strings with the date and time.
Now you wanted a unique list based on the date not the time, so when we get the data from the collection we change it to pure dates instead of dates and time.
This gives us the opertunity to later seperate them to have just 1 of the same date.
@volkaertskristof ok, so now we have extracted data from database to array, now we need to get Unique list based on the date which is another function. and than? The loop us used due to async “promises” method? Can you share an example?
Hi Jan,
Atm i’m in the hospital.
I wil try to respond (if i don’t forget) when i’m out, don’t know when that will be
@volkaertskristof By the way, get well soon (ninja).
@volkaertskristof Hi Kristof, don’t worry with replay. The most important thing is to get recover soon. Take care and thank you very much for your help.


