On my site I would like to count members (#text50) who activated their profile and show it on a dynamic page:
My code is:
export function text50_viewportEnter(event, $w) { let category = $w("#dropdown1").value; let counter = 0; wixData.query("Members") .eq("_id", wixUsers.currentUser.id) .isEmpty("membercategory") .count() .then((empty) => { if(empty===1){ $w("#text50").text = "--"; $w("#html1").hide(); $w("#button10").disable();} else { wixData.query("Members") .eq("membercategory", category) .between("validityday", 0,31) .find() .count() .then((number) => { counter = number; $w("#text50").text = counter.toString(); if (counter >20){ $w("#html1").hide() $w("#button10").disable(); } }); } }); }
I collect an input value to get members 'category' and if it's empty disable the count, if not empty run query to count.
1st condition is the 'membercategory', it works fine!
2nd condition is the 'validityday', I generated in backend like this:
export function Members_afterQuery(item, context) { var payment_date = new Date (item.lastpaymentdate); var today_date = new Date(); item.validityday = 30 - (Math.floor((today_date - payment_date) / (1000*60*60*24))); return item; }
My huge problem is '.between' condition does not work for that calculated field.
I tried .gt, .lt, etc. but is seems this field do not cooperate with this query.
How can I put that important condition in the code?
My site url is:
https://www.wedmet.net
If somebody register the next page is that dynamic page with this counter on it.
Thanks in advance!
I put a console.log() statement in your calculation for validitydays in the backend and I see it's getting NaN. Could be because the lastPaymentDate field is null for all rows except one.
We are unable to invest a lot in debugging site code and we do not rewrite code for users, but we provide the directions and tools to overcome the issues they're facing. When you have things worked out we'll be glad to assist with issues and questions you might have.
Yep but e.g. if I register a new member with the same category and activate it the counter is still the same.
Seems like it works for me:
On my site I would like to count members (#text50) who activated their profile and show it on a dynamic page ("Members ID":
My code is:
export function text50_viewportEnter(event, $w) { let category = $w("#dropdown1").value; let counter = 0; wixData.query("Members") .eq("_id", wixUsers.currentUser.id) .isEmpty("membercategory") .count() .then((empty) => { if(empty===1){ $w("#text50").text = "--"; $w("#html1").hide(); $w("#button10").disable();} else { wixData.query("Members") .eq("membercategory", category) .between("validityday", 0,31) .count() .then((number) => { counter = number; $w("#text50").text = counter.toString(); if (counter >20){ $w("#html1").hide() $w("#button10").disable(); } }); } }); }
I collect an input value to get members 'category' and if it's empty disable the count, if not empty run query to count.
My problem is the counter do not show the right numbers (members number in a category with validitiday between 0-31).
'validityday'is generated in backend like this:
export function Members_afterQuery(item, context) { var payment_date = new Date (item.lastpaymentdate); var today_date = new Date(); item.validityday = 30 - (Math.floor((today_date - payment_date) / (1000*60*60*24))); return item; }
It works fine.
My site url is:https://www.wedmet.netIf somebody register the next page is that dynamic page with this counter on it.
This 2 condition is so easy and simple so I do not understand what is wrong with it.
Thanks in advance!
I don't know what your code looks like and I don't know what page all this happens on.
E.g. I have to submit the collection (save button with submit function to database) twice and the result in counter only appearing after the 2nd submit. What is the matter with the first?
Thx Yisrael,
yep you got the truth so I clear out my chaos, restructure my code and check errors as well.
Now no errors, I got only one onReady handler but that counter still not working well :(
Do you have any idea?
Thx in advance!
Imre
Hi,
You have two instances of the $w.onReady(function(){} event handler in the code for that page. This will result in unpredictable behavior. The first instance should end up overriding the first instance.
In addition, you also have similar code in the site code panel. This causes several errors that appear in the Developers console.
These problems will have to be fixed before the code can be checked effectively.
Good luck,
Yisrael