Dave,I have modified your code to allow for configuration from the EditWidget XML configuration file.Add the following to EditWidget.xml:
<editablelayer>
<layername>Sample Layer</layername>
<fieldnames>FIELD1,FIELD2</fieldnames>
<fieldlabels>Field1,Field2</fieldlabels>
<hiddenfields>FIELD3</hiddenfields>
</editablelayer>
Within the EditWidget.mxml file:
[Bindable]
private var showAttributesText:String;
/* MODIFICATION -- setup variables for FieldInspector values from configXML */
private var editableLayerName:String;
private var editableLayerFieldNames:Array;
private var editableLayerFieldLabels:Array;
private var editableLayerHiddenFields:Array;
/* MODIFICATION -- END */
private function basewidget_widgetConfigLoaded(event:Event):void
{
// hide map infowindow if any
map.infoWindow.hide();
if (configXML)
{
// MODIFICATION -- load configuration values for FieldInspector into variables
editableLayerName = configXML.editablelayer.layername;
if (configXML.editablelayer.fieldnames.length() > 0)
{
// add field names to array
editableLayerFieldNames = [];
const tempFieldArray:Array = configXML.editablelayer.fieldnames.split(",");
for (var count1:Number = 0; count1 < tempFieldArray.length; count1++)
{
editableLayerFieldNames.push(tempFieldArray[count1]);
}
}
if (configXML.editablelayer.fieldlabels.length() > 0)
{
// add field labels to array
editableLayerFieldLabels = [];
const tempLabelArray:Array = configXML.editablelayer.fieldlabels.split(",");
for (var counter2:Number = 0; counter2 < tempLabelArray.length; counter2++)
{
editableLayerFieldLabels.push(tempLabelArray[counter2]);
}
}
if (configXML.editablelayer.fieldlabels.length() > 0)
{
// add names of hidden fields to array
editableLayerHiddenFields = [];
const tempHiddenFieldArray:Array = configXML.editablelayer.hiddenfields.split(",");
for (var count3:Number = 0; count3 < tempHiddenFieldArray.length; count3++)
{
editableLayerHiddenFields.push(tempHiddenFieldArray[count3]);
}
}
// MODIFICATION -- END
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];
}
// 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";
}
// MODIFICATION -- call function to setup FieldInspector
createFieldInspectors();
// MODIFICATION -- END
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():void
{
editor.attributeInspector.formItemsOrder = "fieldInspector";
var layer:Layer;
var fLayer:FeatureLayer;
layer = map.getLayer(editableLayerName);
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);
}
}