The user saves their preferences when they create a profile. These preferences are put into the userProfile database. I know this height filter should work because I tested it using an input box, but now that I’m taking the input from the database it doesn’t work. The gender filter does though. The rest don’t work either.
$w.onReady(function () {
$w("#dataset1").onReady(() => {
makeRepeater();
wixData.query("userProfile")
.eq("_owner", user.id)
.find()
.then((results) => {
let firstItem = results.items[0];
$w("#dataset1").setFilter(wixData.filter()
.ne("gender", firstItem.gender)
.ge("height", firstItem.heightPref)
.le("dob", firstItem.ageupperPref)
.ge("dob", firstItem.agelowerPref)
);
});
})
});
Hi Reeshyal,
Looking at this I’m wondering what field type heightPref is. Could you post a screen shot of the collection from the content manager?
heightPref is a text field. The other two are date fields. If I change the order of the filters, then gender stops working too.
Is the field named “height” in the collection tied to dataset1 also a text field?
What happens if you remove the gender filter?
It should work, but 5’10 and 5’11 will not filter in the way you would hope. In other words, ge 5’8 would include 5’8 and 5’9 but would not include 5’10 and 5’11.
By the way, in the United States 5’8 is five feet eight inches, and 5’11 is five feet and 11 inches. I’m not entirely sure the whole world does it that way?
If I remove the gender filter, none of them work. The repeater is blank. For the height, what would you suggest is the best way to filter it? I mean the filter for the age is terrible too because I can’t just ask my users for an age, I have to ask them for a date since it uses their birthday to filter.
If you had a function that converts the feet and inches of heightPref to a numeric inches field, that would be the cleanest and not prone to the issue noted above. Or you could simply create a lookup collection with those two fields (height and heightInches), populate it with all of the possible heights, and have that be the data source for the dropdown. You would then store the inches the user enters, and that would be the field the filter uses.
Thanks, I can try that. Any idea on how to get the other filters to work? I still don’t understand why only the gender one works and only if you put it first.
Nothing is coming to mind about what the issue might be with the gender filter having to be first.
Though I get why asking for a user’s age is problematic, I’m not understanding how the upperPref and lowerPref approach solves the problem.
What are you trying to accomplish? Do you have a gender field? What are the possible values?