Select to view content in your preferred language

Default Date in Attribute Inspector

2566
8
08-20-2010 10:02 AM
PaulSchneider
Regular Contributor
How can I modify the default date of the 'Date Picker' calendar in the Attribute Inspector.  In other words, when the Attribute Inspector recognizes a 'Date' field type, the Date Picker defaults to the field's value.  I would like to program it for today's date.

Thanks-
Tags (2)
0 Kudos
8 Replies
DavidFlack
Regular Contributor
Paul,

Did you have any luck in resolving this?  I have the same question too.

Dave
0 Kudos
PaulSchneider
Regular Contributor
Seems like a rather simple fix doesn't it?   ...no luck yet
0 Kudos
DavidFlack
Regular Contributor
I figured this one out.  I'm working with the Edit Widget, but the solution should be similar to yours.
The line I commented out was trying to grab the date from the field.  I don't have that in my case.  I also moved feature.attributes[field.name]= date.time; out if the IF block- it only populates the box if the time is 999ms after the second...

Hope that helps you.

private function featureLayer_selectionComplete(event:FeatureLayerEvent):void
{
   for each (var field:Field in event.target.layerDetails.fields)
   {
       if (field.type == Field.TYPE_DATE)
       {
           for each (var feature:Graphic in event.features)
           {
               //var date:Date = new Date(feature.attributes[field.name]);
               var date:Date = new Date();
               if (date.milliseconds == 999)
               {
                   date.milliseconds++; //Add 1ms to date values ending in 999 to workaround REST  
                                              //date bug
               }
   feature.attributes[field.name] = date.time;
             }
        }
    }
}
0 Kudos
PaulSchneider
Regular Contributor
David-

I tried this and it works with one catch, every time a feature is selected the value updates to today's date, whether one wants it to or not.

I don't want the attribute value to automatically change, but rather the default date in the date picker to always be today's date; or at least have that option.

Thanks but still searching for a solution...
0 Kudos
FrankRoberts
Frequent Contributor
I think the above code might be close to helping me through a problem I am having, but I am a little stuck.  My desire is to automaticly populate the popup with when the end user finishes completing the drawing.  I have added a little bit of code to find the field I am looking for (in this case Event_Name).  However, I'm stuck on how to update the feature with the value.  Would one of you be able to provide me with the missing link in my code?  Below is what I have so far:



private function featureLayer_selectionComplete(event:FeatureLayerEvent):void
   {
    for each (var field:Field in event.target.layerDetails.fields)
    {
     // added by fr next 5 lines
     if (field.name == "Event_Name"){
      trace ("I found the  called Event_Name!!!");
      // I want to do something like below, but this doen't work:
      //feature.attributes[field.name] = "this is a test";      
     }
     
     if (field.type == Field.TYPE_DATE)
     {
      for each (var feature:Graphic in event.features)
      {
       var date:Date = new Date(feature.attributes[field.name]);
       if (date.milliseconds == 999)
       {
        date.milliseconds++; //Add 1ms to date values ending in 999 to workaround REST date bug
        feature.attributes[field.name] = date.time;
       }       
      }
     }
    }
   }



Thanks for your assistance,
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Frank,

   You have found the field but you don't have a reference to the feature yet in your code.
See if this works:

private function featureLayer_selectionComplete(event:FeatureLayerEvent):void
            {
                for each (var field:Field in event.target.layerDetails.fields)
                {
                    // added by fr next 5 lines
                    if (field.name == "Event_Name"){
                        trace ("I found the  called Event_Name!!!");
                        // I want to do something like below, but this doen't work:
                        for each (var feature:Graphic in event.features)
                        {
                            feature.attributes[field.name] = "this is a test";
                         }                        
                    }
                    
                    if (field.type == Field.TYPE_DATE)
                    {
                        for each (var feature:Graphic in event.features)
                        {
                            var date:Date = new Date(feature.attributes[field.name]);
                            if (date.milliseconds == 999)
                            {
                                date.milliseconds++; //Add 1ms to date values ending in 999 to workaround REST date bug
                                feature.attributes[field.name] = date.time;
                            }                            
                        }
                    }
                }
            }
0 Kudos
FrankRoberts
Frequent Contributor
Thanks Roberts, that was just the ticket!
0 Kudos
FrankRoberts
Frequent Contributor
Robert, on first blush that seemed to work.  My attributes get pushed to the popup window, however they don't seem to be saved back to the data in SDE.  If I reload the map or look at it in AC the attributes are blank, though the feature is there.  I've added some trace functions and can see that the featureLayer_selectionComplete function runs to completion.  I am seeing the following warning after the featureLayer_selectionComplete finishes:

warning: unable to bind to property 'graphicsLayer' on class 'com.esri.ags::Graphic'

Just to clarify. After closing the edit widget.  The graphic and attributes looks just like the other features in the layer I am editing, and there values seem to be intact per the mod above. 

My goal here is to simplify the editing process for the end user, basically by creating a fill in form, having the user complete that first, and then having them trace the feature on the screen.  If there is a better way to attempt this I'm all ears.

Any ideas?
Thanks in advance.
0 Kudos