ESRI Popup Date

580
3
02-15-2017 04:23 PM
by Anonymous User
Not applicable

Hi all,

I am creating a popup programmatically and it works fine but I am not sure how to not return the default computer date value of "december 31st 1969" when date is empty. I started with an if statement line 7 but not too sure how to return a "No Value" if no date value in th epopup. Any idea?

function getTextContent(graphic) {
          var phone = graphic.attributes.Public_Contact;
          var rs = graphic.attributes.BLOCKNM;
          var comment = graphic.attributes.COMMENT;
          var fc = graphic.attributes.FULLCLOSE;
          var Loc = graphic.attributes.LOCDESC;
          if(graphic.attributes.Estimated_End == "") {
             content += "<br/><b>No Value</b>";  
           }
          var lastupdated = locale.format(new Date(graphic.attributes.LASTUPDATE), {
              selector: 'date',
              datePattern: 'MMMM d, y',
              time: "h:m:s.SSS a z",
           });
           var eed = locale.format(new Date(graphic.attributes.Estimated_End), {
              selector: 'date',
              datePattern: 'MMMM d, y'
           });
           var starts = locale.format(new Date(graphic.attributes.STARTDATE), {
              selector: 'date',
              datePattern: 'MMMM d, y'
           });
          return "<b>Road Status: </b>" + rs + "<br>" +
          "<b>Comments: </b>" + comment + "<br>" +
          "<b>Full Closure: </b>" + fc + "<br>" +
          "<b>Location: </b>" + Loc + "<br>" +
          "<b>Starts: </b>" + starts + "<br>" +
          "<b>Estimated End Date: </b>" + eed + "<br>" +
          "<b>Public Contact Information: </b>" + "<a href=tel:" + phone + ">" + phone + "</a><br>" +
          "<b>Last Updated: </b>" + lastupdated + "<br>" 
          }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Alex,

   Check is graphic.attributes.LASTUPDATE is null before you try an convert it to t date.

0 Kudos
SteveCole
Frequent Contributor

I found a function online for testing empty variables and I've been using that:

function empty(data) {
     //Taken from:
     //https://www.sitepoint.com/testing-for-empty-values/
     if(typeof(data) == 'number' || typeof(data) == 'boolean')
     { 
          return false; 
     }
     if(typeof(data) == 'undefined' || data === null)
     {
          return true; 
     }
     if(data.indexOf(' ') >= 0 && data.length == 1 )
     {
          return true;
     }
     if(typeof(data.length) != 'undefined')
     {
          return data.length == 0;
     }
     var count = 0;
     for(var i in data)
     {
          if(data.hasOwnProperty(i))
          {
               count ++;
          }
     }
     return count == 0;
}

And I use it like this:

thePrjName = (empty(attrib.prjName)) ? "Unspecified" : attrib.prjName;

If you're not familiar with that, it's an if..then conditional statement as one line of code:

conditional ? true : false

Steve

AaronBooterbaugh
Occasional Contributor

I modified your function for the field specified. Try this...

function getTextContent(graphic) {
          var phone = graphic.attributes.Public_Contact;
          var rs = graphic.attributes.BLOCKNM;
          var comment = graphic.attributes.COMMENT;
          var fc = graphic.attributes.FULLCLOSE;
          var Loc = graphic.attributes.LOCDESC;
          var lastupdated = null;
          var eed = null;
          var starts = null;
          lastupdated = locale.format(new Date(graphic.attributes.LASTUPDATE), {
              selector: 'date',
              datePattern: 'MMMM d, y',
              time: "h:m:s.SSS a z",
           });
           if(graphic.attributes.Estimated_End === null) {
             eed = "No Value";
           } else {
             eed = locale.format(new Date(graphic.attributes.Estimated_End), {
                selector: 'date',
                datePattern: 'MMMM d, y'
             });
           }
           starts = locale.format(new Date(graphic.attributes.STARTDATE), {
              selector: 'date',
              datePattern: 'MMMM d, y'
           });
          return "<b>Road Status: </b>" + rs + "<br>" +
          "<b>Comments: </b>" + comment + "<br>" +
          "<b>Full Closure: </b>" + fc + "<br>" +
          "<b>Location: </b>" + Loc + "<br>" +
          "<b>Starts: </b>" + starts + "<br>" +
          "<b>Estimated End Date: </b>" + eed + "<br>" +
          "<b>Public Contact Information: </b>" + "<a href=tel:" + phone + ">" + phone + "</a><br>" +
          "<b>Last Updated: </b>" + lastupdated + "<br>"
          }