I am trying to put a calendar ‘’ DatePicker ‘’ in search engine for my repaeater and I do not know how to make it work …
Here is the code used:
import wixData from ‘wix-data’;
export function button8_click (event) {
$ w (“# dataset1”). setFilter (wixData.filter ()
.contains (“type”, $ w (‘# dropdown7’). value)
.contains (“region”, $ w (‘# dropdown8’). value)
.contains (“title”, $ w (‘# input11’). value) .contains (“date”, $ w (‘# datePicker1’). value)
);
}
There is no error code in the code entered … all the lines work except the last. In my database as the type of field for date I selected the option ‘’ Date and Time ‘’. I don’t know if that’s the problem?
I want the user to be able to choose a date from the “datePicker” to which an element is linked in my database and have the results shown. I don’t know if it’s clearer this way?
In the same way that a customer on AirBnb selects an availability date and only the available accommodations appear.
@keenanfillion62126 You probably want .eq() rather than .contains(). That can compare dates. That’ll be the function you want if you’re looking for an exact match for a given date. You’d need to use .lt() and .gt() if you wanted to support a range of dates.
With .eq() you should be careful about how you handle the time portion of the field. If the database can’t store dates by themselves (I forget) you should maybe set the time to midday both before storing and comparing, but this is a bit hacky and may trip you up if timezones come into play.
Maybe store dates as text (“01/12/2020”) and format the Date value from the calendar input picker to match and compare that with .eq(). That strikes me as the best approach actually. These are the functions you’ll need to build the date string. Be careful that getMonth() returns a 0-indexed value, so you’ll need to add one to it.
@lee1 Hi, it is strange… when i put the .eq instead of .countains. all the items of the repeater disappear when I select the desired date. I entered the same date format as entered in the properties of the “datePicker” but it does not seem to work.
@keenanfillion62126 If you’re using the date datatype in your collection you shouldn’t be formatting what you pass into eq at all: just send the value of the date picker. If that returns nothing it probably means the dates aren’t equal. To debug this retrieve the desired value from the database and console.log it and the date picker value as strings.
I finally found a way to make the code work. I simply separated the 2 groups of codes and since there is no more interference between the commands. everything works fine now! Here is the code used:
import wixData from ‘wix-data’;
export function button8_click(event, $w) {
$w(“#dataset1”).setFilter(wixData.filter()
.contains(“type”, $w(‘#dropdown1’).value)
.contains(“region”, $w(‘#dropdown2’).value)
.contains(“title”, $w(‘#input11’).value)
);
}
export function datePicker1_change(event) {
$w(“#dataset1”).setFilter(wixData.filter()
.eq(“date”, $w(‘#datePicker1’).value)
);
}