Hi! I have a user submission form that the user selects a time when they want their submission to be removed from view. This time populates in a time field in my DB. I have used the code below which was recommended from a previous post, obviously amended it to fit my data, however the code hides all submissions instead of at the time the user selects. Any ideas or amendments to make this work!
$w.onReady( function () {
wixData.query("Timedout")
//find all future dates
.gt(“timer”, new Date())
.find()
.then((results) => {
//setting all the filtered data to the repeater
$w(“#repeater1”).data = results.items;
})
. catch ((err) => { let errorMsg = err;
});
$w(“#dataset1”).refresh();
});
Hi JD, not really. What is supposed to happen is that in my user submission form there is a time picker. The user selects a time In the future and when it gets to that time their submission is hidden/removed from the site. This code seems to hide any submission.
@ibateman37 so check your database, maybe the “timer” values there are wring, because your query is set to show only events that their “timer” value is greater from now (and that’s what you want to show, if i got you right).
“timer” is set as a time field not date and time as the users only input the time. I only have limited coding knowledge so I’m unsure if this is causing the issue
new Date() is an exact time stamp (and not only a “date”).
I’m not sure what you mean by “as the users only input the time”.
You should check carefully that the data in your collection is fine.
@jonatandor35 Sorry, I meant the user submission is a time picker, not date and time so I’m not sure if that’s the problem. Everything from the user submission is loading fine into the DB and displaying on the site ok as well
I really don’t get it. Treble checked my DB. The user input time picker is definitely a time field. As this is the only field I’m using in the code I can’t see it’s any other field effecting it.
@ibateman37 what I don’t understand in you code is the last line: $w(" #dataset1 ").refresh(); .
I thought you were trying to populate the repeater based on a direct collection query, so why do you have there a dataset?
@jonatandor35 I have no idea why I put it there! I removed it today and I still have the same issue. Strange thing happening as well, when I’m in both preview or published site there’s no submissions showing - which there shouldn’t be. I go to another page, navigate back and all of the submissions are there that should be filtered and not seen.
@ibateman37 first of all make sure your repeater is not connected to a dataset via the editor.
Second, try to do the following: go to your published site, navigate back (so you’ll have the issue), refresh the page and let us know what you got.
@jonatandor35 I’m not at my laptop at the moment but I do have some elements of my repeater connected to the DB without code. I’ll remove any connections and try it. I’ll post what I get as soon as I can! Thank you so much for you help.
@jonatandor35 I’ve done all of the above and it’s still the same, sometimes showing submissions and sometimes not. I’ve amended the code today and it’s a lot better, not showing any submissions but it’s not showing any new submissions still, hiding everything. I’m not sure it’s got something to do with the .gt(“timer”, new Date()) line…I might be wrong! Here’s my amended code
$w.onReady( function () {
$w(“#repeater1”).hide(); // hide to start
$w(“#dataset1”).onReady( () => {
$w("#dataset1").setFilter(wixData.filter()
.gt("timer", **new** Date())
)
.then( () => {
console.log("Dataset is now filtered");
$w("#repeater1").show(); // show after dataset is filtered
})
. **catch** ( (err) => {
console.log(err);
});
});
@ibateman37 this is a completely different code. Your’e back to data-sets, and now you can connect the elements via the editor.
If you go for that direction, you should write again the $w(“#dataset1”).refresh(); put it inside the “then” block at the end and not like you did before (in the first post, you put the refresh command outside of the “then” block and that means it’d refresh the data-set before you’ve got the results. That’s not what you want) .
@ibateman37 I can’t tell you what’s wrong. What do you see in the console logs + check your database to see the correct times are actually there and make sure.
@jonatandor35 Here’s what my DB looks like for the time field. The time picker on the user submission looks like it’s pulling through fine to me. And this is what my console logs says when the page loads.
@ibateman37 Now I can see the problem. If you care about dates, you should change the field type to ‘Date and Time’ and store the dates there as well.
If you don’t care about the date (let’s say you need it for today only), then you can’t simply use new Date() as is, and you have to process it first (see here about getHours() and getMinutes(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date# )