7

In chrome - I don't know in other browser (and I don't care for this time, but answer are valid for any of them) - if you didn't set the whole date (e.g. missing the hour and minutes --:--), the value of the input is empty...

how can I know what not-empty values was inserted? or chrome waits to set the value of the input until all the fields are all set?

I thinked a brutal method that I don't like: set a default value (e.g. today or 1/1/1970), then chrome has to set the value of the input, then all the values are ok even if the user don't set the date manually.

<input id="INPUT" type="datetime-local" name="ciccio">

The render is something like

**-**-**** --:--

where * are field for the day,month,year.

If you type this:

12-03-2013 --:--

and requesting the value of the INPUT by javascript

console.log($('#INPUT').val());
//the result is "" (nothing).

but something has been inserted

Nereo Costacurta
  • 7,693
  • 4
  • 21
  • 27
  • "The input"... what input? Can you provide some clearer information about what you're talking about. Maybe some sample code. – Dancrumb Jan 29 '14 at 14:02
  • @Dancrumb : sorry, I know I'm not very clear. I updated my question now – Nereo Costacurta Jan 30 '14 at 16:05
  • 1
    I've run into this issue today and I'm trying to find a way to detect that this is the case so the user can be alerted. No luck so far. :/ – Logan Dec 03 '15 at 01:15
  • Just kidding. Calling the 'validity' attribute does the trick. – Logan Dec 03 '15 at 01:17
  • Did you ever solve this? As a workaround, I create two separate fields, one for both date and time, and one with only date. – Michael Apr 14 '16 at 06:19
  • @Logan struggling with same issue, calling 'validity' or checkValidity() does not help me (Chrome) – rluks Dec 11 '16 at 12:36
  • value sanitization algorithm does not allow to read incomplete value see http://stackoverflow.com/questions/26615364/hot-to-get-incomplete-datetime-local-input-values – rluks Dec 11 '16 at 13:19

0 Answers0