The datetime-local
html input type accepts a value in the format 2021-12-04T18:45
, however my app uses dates in the 2021-12-04 18:45
format, so I’m trying to change the value of the datetime-local input with JavaScript on form submit:
document.getElementById('myform').onsubmit = (event) => {
let _form = event.target;
_form.elements.namedItem('date_from').value = '2021-12-10 20:50';
};
but get the following error:
The specified value “2021-12-10 20:50” does not conform to the
required format. The format is “yyyy-MM-ddThh:mm” followed by
optional “:ss” or “:ss.SSS”.
How do I bypass the formatting enforcement in this scenario?
I’d prefer using datetime-local
input type, to take advantage of the built-in date and time picker as opposed to having to use extra library. So changing the input field type would not be a preferable solution.
P.S. I cannot control the backend processing of the form, so I have to change the value in the frontend before the form is submitted further.