top of page

You may submit a time

(Go ahead and play with it)

Choose a time

FAILED

SAVED

Last submitted time:

//CODE:

import wixData from'wix-data';

let dateTime;

$w.onReady(function () {

//Here I search for the last submission:

showlastSubmission();

function showlastSubmission(){

    wixData.query("Reservations")

    .descending("_createdDate")

    .limit(1)

    .find()

    .then((res) => {

        console.log("found");

        $w("#lastEvent").text = "last submitted time (received from collection query): \n" + res.items[0].dateTime.toLocaleString();

    })

    .catch((err) => {

    console.log("error");

})

    }

//This is the selected time parsing:

$w("#datePicker1, #timePicker1").onChange((event) => {

if($w("#timePicker1").valid && $w("#datePicker1").valid){

let timeSplit = $w("#timePicker1").value.split(":");

let timeInMs = Number(timeSplit[0]) * 3600000 + Number(timeSplit[1]) * 60000;

dateTime = new Date($w("#datePicker1").value.getTime() + timeInMs);

}

})

//Submission:

$w("#submitButton").onClick((event) => {

    wixData.save("Reservations", {"dateTime": dateTime})

    .then(() => {

        $w("#successMsg").show();

        showlastSubmission();

        setTimeout(() => {$w("#successMsg").hide();}, 3000);        

})

.catch((err) => {

    $w("#failedMsg").show();

    setTimeout(() => {$w("#failedMsg").hide();}, 3000)

})

})

})

FOOTER

bottom of page