Relatively new to Angularjs
I have read the date input documentation here: Angularjs Date Input It states the model (the data the input is bound to) must be a JavaScript date object.
However, in my application, I want to be able display a date input field that is initially empty (except perhaps for a placeholder prompt). If the user chooses not to enter a date, that is an acceptable circumstance.
My understanding is that a JavaScript date object always describes some date. So the date input, since it is bound to the model, will always display some date. And if the user overlooks or skips the date input, a date will still seem to have been provided. I don't want that to happen.
The only solution I have think of would be to use a text edit field that can be empty or contain a date. And then I would have to somehow parse out the user input. But it wouldn't have a nice date picker.
Any suggestions on how to solve this issue?
Well, you can actually simply set the value to undefined.
$scope.value = undefined
won't throw an error.
See working plunkr : http://plnkr.co/edit/5Nf9UeC5XApAAST1eRJX?p=preview (Edited from previous reply by OP.)
As mentioned by Tete1805, it is the correct solution.
Just wanted to share a case i had experienced in this regard. A case in which it was returning me a value like "0NaN-NaN-NaN
" that's while using : document.getElementById('date'+index).value;
It can be resolved by simply checking
if(document.getElementById('date'+index).value == "0NaN-NaN-NaN"){
//Error handling code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With