Hello!
I have issues with the dropdown component because it’s skipping some of the choices(values) in it.
It gets its values from the bookings api and I have followed this* tutorial and have used the same code.
Some of the timeslots get skipped. Look at the attachments for example, I cannot choose 12:20 even though its available. It jumps to 12:10 instead. I have tested on different browsers and computers. The issue persists. It’s different timeslots that are troublesome each time.
this tutorial* https://www.wix.com/corvid/example/quick-book-and-pending-appointments
Code below:
$w("#dayPicker").onChange((event, $w) => {
const selectedDate = new Date(event.target.value);
findAvailableSlots(selectedDate);
});
$w("#submitButton").onClick(() => validateAndSubmitForm());
});
let slotsMap = {};
async function findAvailableSlots(dateString) {
slotsMap = {};
const startDateTime = getMidnight(dateString);
const endDateTime = getNextMidnight(dateString);
const options = {
startDateTime,
endDateTime
};
const availableSlots = await getNonPendingAvailableSlots(serviceId, options);
if (availableSlots.length === 0) {
$w("#slotPicker").options = [];
$w("#slotPicker").placeholder = "No sessions this day";
$w("#slotPicker").selectedIndex = undefined;
$w("#slotPicker").disable();
}
else {
$w("#slotPicker").options = availableSlots.map(slot => {
const uniqueId = new Date().getUTCMilliseconds().toString() // Generate a short unique ID to
slotsMap[uniqueId] = slot;
let startTime = slot.startDateTime;
let timeString = getTimeOfDay(startTime);
return {
label: timeString,
value: uniqueId
}
});
$w("#slotPicker").placeholder = "Pick a time";
$w("#slotPicker").selectedIndex = undefined;
$w("#slotPicker").enable();
}
}
async function getNonPendingAvailableSlots(requestedServiceId, options = {}) {
const pending = (await getPendingAppointments()).map(appointment => appointment.requestedSlot._id);
let availableSlots = (await wixBookings.getServiceAvailability(requestedServiceId, options)).slots;
availableSlots = availableSlots.filter(slot => !pending.includes(slot._id));
return availableSlots;
}
async function getPendingAppointments() {
return (await wixData.query("pendingAppointments").find()).items.filter(item => item.status === "PENDING");
}
function getMidnight(date) {
let midnight = new Date(date);
midnight.setHours(0, 0, 0, 0);
return midnight;
}
function getNextMidnight(date) {
let midnight = new Date(date);
midnight.setHours(24, 0, 0, 0);
return midnight;
}
function getTimeOfDay(date) {
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }).toLowerCase();
}
Have anyone experienced this type of issues before with the dropdown component?