Select to view content in your preferred language

Edit Widget Questions

5037
42
09-28-2010 10:14 AM
JasonNielsen
Regular Contributor
Is there a way to change the order of the attribute fields in the edit widget so they are not alphabetical but rather following the order they are in the xml file?

My second question is 2.0 didn't support snapping but it was mentioned that it would be something later on. Can somebody let me know when they think this would be implemented?

Thanks,

Jason
Tags (2)
0 Kudos
42 Replies
HaroldBostic
Frequent Contributor
Thank you all.  I modified the code above to work with multiple editable layers

Add the following to the editwidget.xml
<editablelayers>
     <editablelayer>
   <layername>Sample Layer</layername>
   <fieldnames>FIELD1,FIELD2</fieldnames>
   <fieldlabels>Field1,Field2</fieldlabels>
   <hiddenfields>FIELD3</hiddenfields>
             </editablelayer>
             <editablelayer>
   <layername>Sample Layer 2</layername>
   <fieldnames>FIELD1,FIELD2</fieldnames>
   <fieldlabels>Field1,Field2</fieldlabels>
   <hiddenfields>FIELD3</hiddenfields>
             </editablelayer>
<editablelayers>


Within the EditWidget.mxml file:
private function basewidget_widgetConfigLoaded(event:Event):void
            {
                // hide map infowindow if any
                map.infoWindow.hide();

                if (configXML)
                {

                    geometryService.url = configXML.geometryservice;

                    const configToolbarVisible:Boolean = configXML.toolbarvisible == "true";
                    editor.toolbarVisible = configToolbarVisible;

                    const configToolbarCutVisible:Boolean = configXML.toolbarcutvisible == "true";
                    editor.toolbarCutVisible = configToolbarCutVisible;

                    const configToolbarMergeVisible:Boolean = configXML.toolbarmergevisible == "true";
                    editor.toolbarMergeVisible = configToolbarMergeVisible;

                    const configToolbarReshapeVisible:Boolean = configXML.toolbarreshapevisible == "true";
                    editor.toolbarReshapeVisible = configToolbarReshapeVisible;

                    if (configXML.createoptions.length() > 0)
                    {
                        createOptions.polygonDrawTools = new Array();
                        createOptions.polylineDrawTools = new Array();

                        if (configXML.createoptions.polygondrawtools.length() > 0)
                        {
                            const polygonDrawToolsList:Array = configXML.createoptions.polygondrawtools.split(",");
                            for (var i:Number = 0; i < polygonDrawToolsList.length; i++)
                            {
                                createOptions.polygonDrawTools.push(polygonDrawToolsList);
                            }
                        }

                        if (configXML.createoptions.polylinedrawtools.length() > 0)
                        {
                            const polylineDrawToolsList:Array = configXML.createoptions.polylinedrawtools.split(",");
                            for (var j:Number = 0; j < polylineDrawToolsList.length; j++)
                            {
                                createOptions.polylineDrawTools.push(polylineDrawToolsList);
                            }
                        }
                        editor.createOptions = createOptions;
                    }
                    //excludeLayers
                    excludeLayers = [];
                    var layers:XMLList = configXML.excludelayer as XMLList;
     
                    for (var n:Number = 0; n < layers.length(); n++)
                    {
                        excludeLayers.push(layers.toString());
                    }

                    //deleteFeatures
                    if (configXML.deletefeatures.length() > 0)
                    {
                        deleteFeatures = configXML.deletefeatures == "true";
                    }
                    editor.deleteEnabled = attachmentInspector.deleteEnabled = deleteFeatures;


                    //labels
                    if (configXML.labels.attributeslabel[0])
                    {
                        attributesLabel = configXML.labels.attributeslabel[0];
                    }
                    if (configXML.labels.attachmentslabel[0])
                    {
                        attachmentsLabel = configXML.labels.attachmentslabel[0];
                    }
     
     /*MODIFICATIONS */
     var editablelayers:XMLList = configXML.editablelayers as XMLList;
     var editableLayerFieldNames:Array;
     var editableLayerFieldLabels:Array;
     var editableLayerHiddenFields:Array;
     
     for each(var eLayer:XML in  editablelayers.children())
     {
       
      
      if (eLayer.fieldnames.length() > 0)
      {
       // add field names to array
       editableLayerFieldNames = [];
       
       const tempFieldArray:Array = eLayer.fieldnames.split(",");
       for (var count1:Number = 0; count1 < tempFieldArray.length; count1++)
       {
        editableLayerFieldNames.push(tempFieldArray[count1]);
       }
      }
      
      if (eLayer.fieldlabels.length() > 0)
      {
       // add field labels to array
       editableLayerFieldLabels = [];
       
       const tempLabelArray:Array = eLayer.fieldlabels.split(",");
       for (var counter2:Number = 0; counter2 < tempLabelArray.length; counter2++)
       {
        editableLayerFieldLabels.push(tempLabelArray[counter2]);
       }
      }
      
      if (eLayer.fieldlabels.length() > 0)
      {
       // add names of hidden fields to array
       editableLayerHiddenFields = [];
       
       const tempHiddenFieldArray:Array = eLayer.hiddenfields.split(",");
       for (var count3:Number = 0; count3 < tempHiddenFieldArray.length; count3++)
       {
        editableLayerHiddenFields.push(tempHiddenFieldArray[count3]);
       }
      }
      
      createFieldInspectors(eLayer.layername,editableLayerFieldNames,editableLayerFieldLabels,editableLayerHiddenFields);
     }
     
     // MODIFICATION -- END
     
                    // featurelayernotvisibletext
                    EditWidgetTemplatePickerSkin.featureLayerNotVisibleText = configXML.featurelayernotvisibletext || "feature layer is either not visible or out of scale range";
                    // showattachmentstext
                    EditWidgetAttributeInspectorSkin.showAttachmentsText = configXML.showattachmentstext || "Show Attachments";
                    // showattributestext
                    showAttributesText = configXML.showattributestext || "Show Attributes";
     
     
                }
    

                map.infoWindow.addEventListener(Event.CLOSE, infoWindowCloseHandler);
                ViewerContainer.dispatchEvent(new AppEvent(AppEvent.DATA_OPT_LAYERS, null, getOplayers));
            }


And add the following function to EditWidget.mxml as well:
// This function establishes the attribute edit environment.
   // In particular, the order in which fields are presented,
   // and the labels attached to those fields.  Lastly, fields
   // that should not be user editable are made not visible.
   private function createFieldInspectors(editableLayerName:String,
               editableLayerFieldNames:Array,
               editableLayerFieldLabels:Array,
               editableLayerHiddenFields:Array):void
   {
    editor.attributeInspector.formItemsOrder = "fieldInspector";
    var layer:Layer;
    var fLayer:FeatureLayer;
    
    layer = map.getLayer(editableLayerName);
    //if layer is null, you entered the wrong name in the layername tag of the specific editablelayer
    if(!layer) return;
    fLayer = layer as FeatureLayer;
    
    var field:FieldInspector;
    var fieldHidden:FieldInspector;
    
    // Setup FieldInspectors for visible fields
    // Assumption: both editableLayerFieldNames and editableLayerFieldLabels will have the same number of elements
    for (var i:Number = 0; i < editableLayerFieldNames.length; i++)
    {
     
     field = new FieldInspector();
     field.featureLayer = fLayer;
     field.fieldName = editableLayerFieldNames;
     field.label = editableLayerFieldLabels;
     editor.attributeInspector.fieldInspectors.push(field);
    }
    
    // Setup FieldInspectors for hidden fields
    for (var j:Number = 0; j < editableLayerHiddenFields.length; j++)
    {
     fieldHidden = new FieldInspector();
     fieldHidden.featureLayer = fLayer;
     fieldHidden.fieldName = editableLayerHiddenFields;
     fieldHidden.visible = false;
     editor.attributeInspector.fieldInspectors.push(fieldHidden);
    }
   }
0 Kudos
JonFisher
Emerging Contributor
This is really helpful, any chance of uploading this as a custom widget (both compiled and source code) to the code gallery to make it easier to find? I'm happy to make the changes in FlexBuilder, but everyone has it. I think I'm going to keep the original edit widget as well, so people can choose from the default one which requires less work to configure, and this one which provides much more customization. Thanks for all the code!
0 Kudos
ThomasSchultz
Deactivated User
This post has been really helpful.  However, I am having trouble setting the AttributeInspector formItemsOrder property.  This should be really easy and straightforward.  I'm using the function below to create my field inspectors and set the formItemsOrder property, the same way that others have done in the post.  But my fields are still not in the correct order, and when I debug I find that the formItemsOrder property is still set to the default "label" value.  Anyone have any idea why the formItemsOrder property won't set for me?

private function createFieldInspectors():void
   {
    var layer:Layer;
    var fLayer:FeatureLayer;
   
    layer = map.getLayer(editableLayerName);
    fLayer = layer as FeatureLayer;
    
    editor.attributeInspector.formItemsOrder = "fieldInspector";
    
    var field:FieldInspector;
    var fieldHidden:FieldInspector;
    
    // Setup FieldInspectors for visible fields
    // Assumption: both editableLayerFieldNames and editableLayerFieldLabels will have the same number of elements
    for (var i:Number = 0; i < editableLayerFieldNames.length; i++)
    {
     field = new FieldInspector();
     field.featureLayer = fLayer;
     field.fieldName = editableLayerFieldNames;
     field.label = editableLayerFieldLabels;
     editor.attributeInspector.fieldInspectors.push(field);
    }
    
    // Setup FieldInspectors for hidden fields
    for (var j:Number = 0; j < editableLayerHiddenFields.length; j++)
    {
     fieldHidden = new FieldInspector();
     fieldHidden.featureLayer = fLayer;
     fieldHidden.fieldName = editableLayerHiddenFields;
     fieldHidden.visible = false;
     editor.attributeInspector.fieldInspectors.push(fieldHidden);
    }
   }
0 Kudos
ThomasSchultz
Deactivated User
Sorry, I was debugging at the wrong point.  Setting the formItemsOrder property to "fieldInspector" is not my issue.  My field inspectors are also creating correctly.  But my fields are still out of order.  Any help would be greatly appreciated.
0 Kudos
by Anonymous User
Not applicable
Greetings all!

I'm finding the code samples here to be very useful, especially the extention of functionality controlled by the EditWidget.xml file, but can anyone point me to a good comprehensive review of all the base tags that the EditWidget understands out of the box? Or are the ones that come in the base widget xml code the only ones that it does? I've been looking for a good disussion on this but have so far not come up with a good definitive answer ...

Case in point, I can add my outFields list directly when coding a FeatureLayer directly in an application but am not finding a compatible xml option in either the base config.xml for the flex viewer or the EditWidget.xml file. Same goes for the ClassBreaksRenderer ...

- Bob
0 Kudos
JonFisher
Emerging Contributor
Greetings all!

I'm finding the code samples here to be very useful, especially the extention of functionality controlled by the EditWidget.xml file, but can anyone point me to a good comprehensive review of all the base tags that the EditWidget understands out of the box?
- Bob


The ESRI help page lists the tags that work out of the box:
http://help.arcgis.com/en/webapps/flexviewer/help/index.html#/Edit_widget/01m30000000v000000/
0 Kudos
NeoGeo
by
Frequent Contributor
Just trying to get the code posted here to work but not having much luck.  I am trying the last version posted.  In the xml posted a closing slash is missing on one of the tags, I added import com.esri.ags.components.supportclasses.FieldInspector because the compiler didn't know what a field inspector was, and I added back in the labels which appeared to have been removed in the posted code (the ok button didn't even have a label), and of course I added the new sections in the xml file.  What else am I missing?  There is no change in the widget's behavior from the original when I run it...
0 Kudos
Ahmad_TarmiziTalib
New Contributor
does these codes work with flexviewer-2.3.1 and acrgis 10 (i notice some differences between the original edit widget code posted above with mine)? i tried both codes too but seems like they did nothing for me. the arrangement is still alphabetical. what could possibly went wrong? =\
0 Kudos
JosVroegop
Deactivated User
Thanks guys, just what i was looking for. 😄

Used the code from Harold Bostic's post in 2.4 viewer, works like a charm.
Esri should make this standard functionality for the edit widget in my opinion.
0 Kudos
dmitrypylnev
Emerging Contributor
Hi! There is a question whether it is possible in a widget in the fields of attributes to write fractions? (field on the GIS server fractional numeric)
0 Kudos