-1

Whenever I try to reset a date input using JavaScript, like so:

//input_id is an id of a date input
document.getElementById(input_id).value = "0000-00-00";

I get a warning in the console:

The specified value "0000-00-00" does not conform to the required format, "yyyy-MM-dd".

Does anyone know a way to suppress this warning so it won't show? The JS keeps on running smoothly but I want to get rid of these warnings.

If you have another way of resetting a date input (without raising a warning) I will be happy to hear.

Thanks in advance.

Alon Alexander
  • 135
  • 3
  • 10
  • I think, its same as: http://stackoverflow.com/questions/20885890/how-do-you-programmatically-clear-html5-date-fields – Vladimir M Oct 13 '16 at 18:09

3 Answers3

2

You're getting the warning because years, months, and days start at 1, not 0. 0 is an invalid value for all of them. But there's a simpler way to reset an input element..

You can just set the value to the empty string which is the initial default value.

var di = document.createElement("input");
di.type = "date";
console.log(di.value); // outputs ""
document.body.appendChild(di);

// change the value if you want

// to reset:
di.value = "";
Shashank
  • 13,713
  • 5
  • 37
  • 63
1

You can assign a empty string value

document.getElementById(input_id).value = "";
0

At the bottom of your Javascript call

console.clear();

This clears all warnings and errors from your console.

You can also replace console.warn with your own code like:

console.warn = function () { };.

NOT recommended because you will not get any warnings to your console this way.

Kellen Stuart
  • 7,775
  • 7
  • 59
  • 82