Disable past dates from default HTML date picker in vanilla JS

915 Views Asked by At

I would like to disable past dates (and times) on my default HTML picker. I didn't create it with any framework, it's just the default one that goes like this:

<label for="time">Date & Time</label>
            <input
            type="datetime-local"
            id="time"
            name="time"
            required>

I have tried this code below for input [type="datetime-local"] that I found but no success yet. All I can find when researching about this is in regards to date pickers in jQuery or disabling date pickers that come from a library/framework.

function datePicker() {
    const formElements1 = form1.querySelectorAll("input, select");
    form1.querySelector("#time").min = new Date().toISOString().split("T")[0]; 
}
0

There are 0 best solutions below