datetime-local value firefox
hi all, i have a problem with the datetime-local tag with firefox.
https://jsfiddle.net/wLtbyx7p/ i have an empty input.
i use the "native interface" to select the date the input is now "12/05/2025 --:--" since i haven't selected a hour yet.
=> since it is not a valid date, the value isn't changed and is still a empty string.
with chrome : when selecting a date, it automatically fills the hour to be "now" therefore, the input is valid and changes.
with firefox, how do i catch the input change from "empty" to "date selected" in order to automatically set the hour to "now" ?
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
14 Replies
you cant - it's an implementation detail of the browser and it doesnt trigger events
you can get around this by using 2 inputs, styled as a single input, that lets you set a date and time
You can auto-fill it yourself:
or that
And, bonus, it auto-fills the date and time on all browsers, so if "today, right now" is a common date/time needed the user doesn't have to do anything :p
that is smart
Yeah, sorry about that
🤣
the broblem is that it musn't be setted unless the user sets it
then you have to go with my solution of having 2 inputs
😢
you can't fix it
you can report it as a bug, if you want
or look for a bug report
i went for an other solution : add a button "add datetime" and when they click : i set the value to "now" 👍
that works too