PopupTemplate : dateFormat

4021
6
08-03-2012 07:42 AM
__Rich_
Occasional Contributor III
Since the dateFormat defers to dojo.date.locale.format anyway, is there a good reason why it's been limited to only support the following:


  •     "shortDate":            "(datePattern: 'M/d/y', selector: 'date')",

  •     "longMonthDayYear":     "(datePattern: 'MMMM d, y', selector: 'date')",

  •     "dayShortMonthYear":    "(datePattern: 'd MMM y', selector: 'date')",

  •     "longDate":             "(datePattern: 'EEEE, MMMM d, y', selector: 'date')",

  •     "shortDateShortTime":   "(datePattern: 'M/d/y', timePattern: 'h:mm a', selector: 'date and time')",

  •     "shortDateShortTime24": "(datePattern: 'M/d/y', timePattern: 'H:mm', selector: 'date and time')",

  •     "longMonthYear":        "(datePattern: 'MMMM y', selector: 'date')",

  •     "shortMonthYear":       "(datePattern: 'MMM y', selector: 'date')",

  •     "year":                 "(datePattern: 'y', selector: 'date')"

?
6 Replies
KellyHutchins
Esri Frequent Contributor
Those are the formatting options available in ArcGIS.com when configuring popups. If you are using the popup in an application built with the ArcGIS API for JavaScript you could apply a custom formatter for your date info by using the InfoTemplate to define the popup content instead of the PopupTemplate.  The InfoTemplate has lots of formatting options including the ability to define a date pattern of your choice:

        var popupTemplate = new esri.InfoTemplate("Test","Date: ${datetime:DateFormat(datePattern: 'h \\'o\\'\\'clock\\' a, zzzz', selector: 'date')} Magnitude: ${magnitude}");
 
        //create a feature layer based on the feature collection
        var featureLayer = new esri.layers.FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer/0", {
          mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
          infoTemplate: popupTemplate,
          outFields: ['datetime','magnitude']
        });


0 Kudos
__Rich_
Occasional Contributor III
Hi Kelly - thanks for the response, but I'm a bit confused - what's the link between this functionality and arcgis.com?

The functionality of the popupTemplate is a better fit than the infoTemplate for what I need - I'm trying to use the off-the-shelf components from the API where possible.

Besides, it looks like PopupBase is re-writing dateFormat settings to DateFormat (as used in infoTemplate) anyway, it's just that it clobbers any formats it doesn't recognise before delegating.  (look for the comment "// guard against unknown format string" in the source)

Tracing through the code it appears all that happens is that the value plus the formatting options get passed to the dojo formatter so I guess I can't see why you wouldn't expose all the dojo functionality?  (or more specifically why there needs to be an intermediate component masking the functionality)

I mean these:

datePattern: 'M/d/y', timePattern: 'h:mm a', selector: 'date and time'

...are dojo.date.locale.format arguments, could the ESRI code be modified to pass them straight through?  It's not like anything's being done to them on the way in, they're just hard-coded in PopupBase.

I suppose I'm thinking that each time you see "dateFormat" then you could just pass the (JSON-defined) value of that straight to dojo.date.locale.format and everyone's a winner 🙂
0 Kudos
KellyHutchins
Esri Frequent Contributor
The Popup is just a custom InfoWindow that adds some additional capabilities like zoom to selected. You can use the Info Template or the PopupTemplate or a function to define the content for your popup window. If your popup window only contains formatted text (numbers, dates, strings etc) then the InfoTemplate with the Popup Window should work just fine.

You are correct in that the PopupTemplate currently only accepts the outlined date formats and anything else you try to provide is overwritten by the defaults. You can submit an enhancement asking that we support this capability by contacting Esri Support.
0 Kudos
__Rich_
Occasional Contributor III
The Popup is just a custom InfoWindow that adds some additional capabilities like zoom to selected.

...and handles attachments automatically, and handles an array of deferreds complete with paging, and handles highlighting features, and looks better etc. 🙂

You can use the Info Template or the PopupTemplate or a function to define the content for your popup window. If your popup window only contains formatted text (numbers, dates, strings etc) then the InfoTemplate with the Popup Window should work just fine.

See above.

....anything else you try to provide is overwritten by the defaults.

Not if you mixin some additional ones 😉

You can submit an enhancement asking that we support this capability by contacting Esri Support.

I hope that some of the enhancements required by customers are picked up from the forum discusssions 😉

Here's my request:

Please allow developers to pass a dojo.date.locale.__FormatOptions object as the value for the dateFormat property of the format object in a fieldInfo element of the object passed to the constructor of PopupTemplate thus removing the restrictions imposed by the current approach.

This will enable, for example, a date/time to be shown in the time zone of the remote user of the system...which is quite a common thing to want to do when you have a global GIS application.

Thanks.
0 Kudos
KellyHutchins
Esri Frequent Contributor
"and handles an array of deferreds complete with paging, and handles highlighting features, and looks better etc."

You can get all that using the InfoTemplate with the PopupWindow. The only thing you miss out on is the easy way to define content (media, images, attachments, charts) via the popup template.
0 Kudos
__Rich_
Occasional Contributor III
"and handles an array of deferreds complete with paging, and handles highlighting features, and looks better etc."

You can get all that using the InfoTemplate with the PopupWindow. The only thing you miss out on is the easy way to define content (media, images, attachments, charts) via the popup template.

Sorry was getting confused between windows and templates!

Yep, but I'm going to want all those other things pretty soon, particularly the attachments.

Thanks for the response, I'm just trying to check my understanding of the limitations.
0 Kudos