Select to view content in your preferred language

Insert text to field when editing

2428
2
11-23-2011 04:27 PM
MarcGuidry
Emerging Contributor
Is it possible to automatically insert a string into a field when editing?  Like if I want to add a user name to every new feature or something like that.
Tags (2)
0 Kudos
2 Replies
IvanBespalov
Frequent Contributor
In this sample find function addFeatureToFeatureLayer

Change it:
private function addFeatureToFeatureLayer(graphic:Graphic):void
{
    if (!doNotAddFeature && myTemplatePicker.
    {
        if (myTemplatePicker.selectedTemplate.featureTemplate)
        {
            var newAtttrs:* = ObjectUtil.copy(myTemplatePicker.selectedTemplate.featureTemplate.prototype.attributes);
            newAtttrs["collection_time"] = new Date();
 newAtttrs["description"] = "Hello world!";
            var newGraphic:Graphic = new Graphic(graphic.geometry, null, newAtttrs);
            myTemplatePicker.selectedTemplate.featureLayer.applyEdits([ newGraphic ], null, null);
        }
        else
        {
            myTemplatePicker.selectedTemplate.featureLayer.applyEdits([ graphic ], null, null);
        }
    }
}


and find function flayer_editsCompleteHandler
Change it:
protected function flayer_editsCompleteHandler(event:FeatureLayerEvent):void
{
    var fer:FeatureEditResults = event.featureEditResults;
    if (fer != null)
    {
        if (fer.addResults != null && fer.addResults.length > 0)
        {
            var addResult:FeatureEditResult = fer.addResults[0];
            var layerUrl:String = FeatureLayer(event.target).url;
      
            if (addResult != null && addResult.success)
            {
                var queryUrl:String = StringUtil.substitute("Inspect just added feature: {0}/query?objectIds={1}&outFields=*&returnGeometry=false", layerUrl, addResult.objectId);
                Alert.show(queryUrl, StringUtil.substitute("Feature added: oid={0}", addResult.objectId));
            }
        }
    }
    trace("e: " + event.toString());
}


Good luck.
0 Kudos
MarcGuidry
Emerging Contributor
Excellent, thanks for the response!  I'm going to try that on monday.

Can this, or a similar method be used when using the Editor component?
Currently I have the editing setup with the editor component.
0 Kudos