Hot to get incomplete datetime-local input data

I have the following form on my page:

<input id='startDate' type='datetime-local' step=1 name='startDate'>

I use this code to get the field value:

var start = $('#startDate').val();

My problem is that the value of the input field remains undefined until each part of it is filled, including hours, minutes, seconds and AM / PM. I would like to be able to get value from a form in just a year.

How can i do this? I'm glad to have zero values ​​that aren't populated, but I can't figure out how to get the portion of the local datetime-local that the user has populated.

I know that I can do this using an addition to the time zone for jQuery UI datepicker, but I really do not want to go this route - I, as a Chrome implementation, are much better.

+3
source share
1 answer

The W3C Date Status Specification defines a disinfection algorithm:

  • The algorithm for deactivating values ​​is as follows: If the element value is not a valid date string, then set it to an empty string instead.

which is called when setting the value of the input element, as defined in the DOM value value spec :

  • , . , true, , , , , , .

, value , . , "// ", .

IMO - , , ( ), .

+1

Source: https://habr.com/ru/post/1524287/


All Articles