Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to know if an input type = datetime-local is halfway filled?

Is it possible to know if an input type = datetime-local is halfway filled? For example, if only the date or time is filled?

<input type="datetime-local" class="form-control input-lg" id="dueDate" 
ng-model="jobDueDate" min="{{currentMin | date:'yyyy-MM-ddTHH:mm'}}" 
placeholder="Due Date" >

The element object value of the input tag is empty no matter if it is empty or halfway filled.

var valuedate = document.getElementById('dueDate');
console.log(valuedate.value());

Date.parse returns NaN as well for both cases. Is there a possible solution? I'm using Jquery & AngularJS if those could help. Feel free to post cleaner solutions using other input types (no extra libraries). The aim is for the user to fill both fields out.

EDIT: Field can either be left blank or fully filled. I need to know if it's half filled so I can prompt the user or calculate the required date myself.

like image 914
Prajeeth Emanuel Avatar asked Jul 25 '16 12:07

Prajeeth Emanuel


People also ask

Can I use input type datetime-local?

One thing the datetime-local input type doesn't provide is a way to set the time zone and/or locale of the date/time control. This was available in the datetime input type, but this type is now obsolete, having been removed from the spec.

What is input type datetime-local?

The input element with a type attribute whose value is " datetime-local " represents a control for setting the element's value to a string representing a local date and time (with no timezone information).

What is the difference between datetime and datetime-local?

The difference between the two is that the datetime-local input does not include the time zone. If the time zone is not important to your application, use datetime-local. Some browsers are still trying to catch up to the datetime input type.


1 Answers

You can detect half-filled field by:

document.querySelector('#dueDate').validity.badInput
like image 123
int32_t Avatar answered Sep 28 '22 07:09

int32_t