Order completing without inputting a field

Hi! I’ve added a custom field to my product page which is a date and time picker. The thing is even without entering the date and time, the add to cart is proceeding which I don’t want as date and time are mandatory. Would love any help with this :confused:

Here’s the link to product page:
Rental Cleaning (renewellcleaners.com)

There isn’t any shortcut way to do this. You have added the date and time picker but there is no validation made in the backend to make that as a mandatory field that user has to fill in. Some javascript has to be added to disable add to cart button unless that field has some value. If you need help on it, just ping me.

Hi @Thehumblelone

You need to add a script in your backend. Please use the code below as reference

const dateInput = document.querySelector('#datetimeinput');
const submitButton = document.querySelector('button[type="submit"]');

dateInput.addEventListener('change', () => {
    if (dateInput.value === '') {
        submitButton.disabled = true;
    } else {
        submitButton.disabled = false;
    }
});

Please don’t forget to Like and Mark Solution to the post that helped you. Thanks!