0

I am trying to avoid passing the null value returned by the server so that invalid date isn't shown on front end. I am referring to the following code :

//var value_ = "2017-06-09 10:05:21.0"

var value_ = null;

if(moment(value_).isValid()){
                        alert(moment(value_).format('MM/DD/YYYY'));

                       }
                       else  {
                        alert("Display Empty String:"+"");
                       }

JSFiddle here:

So, passing empty string " " works well from the UI point of view and I don't see invalid dates for dates which have null values. When I pass the empty string to the server" ", I get an error similar to the one someone is facing here which is obvious because I am passing empty string:

parse a emty string into SimpleDateFormat

Is there a way to overcome this from UI point of view so that I don't see invalid date option just like it's shown in this JSFiddle ?

Dan
  • 443
  • 1
  • 7
  • 19
  • I can't understand what you are trying to get, `moment("")` gives an `Invalid date` as you showed in first fiddle, if you want to avoid it you can use the code of the second fiddle. – VincenzoC Jun 14 '17 at 22:08
  • 1
    @VincenzoC When I use my second fiddle, I am basically sending empty strings to my database `" "` and in that case, I am getting PaseException from Java side. I am wondering how can I avoid sending an empty string to the database and also avoid showing `invalid date` on the UI side? 2) Also wondering, is there a way I can use `moment` which will avoid displaying `invalid date`. Because in my second fiddle, I had to completely get rid of moment to get rid of `invalid date` thing. – Dan Jun 15 '17 at 03:24

0 Answers0