Select to view content in your preferred language

Set Field as Read Only in Attribute Inspector, but remain editable by Editor Widge

1373
1
Jump to solution
10-15-2012 01:11 PM
MeleKoneya
Frequent Contributor
We have an application which allows users to edit Feature Classes in SDE via a Feauture Server.     We have a uniqure identifier field called "Asset_ID" in ten feature layers that will be populated with a unique number each time a feature is added using code similar to that below:

  //Added to update asset_id in feature before editing
            function beforeEdit(layer) {
                dojo.connect(layer, "onBeforeApplyEdits", function (adds, updates, deletes) {
                    dojo.forEach(adds, function (add) {
                        add.attributes.Asset_ID = 1234;
                    });

                });

            }

I would like the Asset_ID field to be read-only to the user so I tried to set the Read Only property for Asset_ID in the MXD when publishing the feature service,   but then my code does not update the field, which makes sense so I have to set the read-only property to "no" for the field in the MXD.

I then tried to change fieldInfos property for Asset_ID to 'isEditable':true for the Feature Layers used by the Attribute Inspector, but the problem I found was that I had to specify each field in the fieldInfos collection that I would like to show in the Attribute Inspector, but our feature classes have different attributes so I feeld it would be cumbersome to handle ten feature layers in this manner.

How can I update the Asset_ID field while showing it as Ready-Only in the Attribute Inpsectore and aslo prevent the user from changing its value.

Thanks for any assistance.

Mele
0 Kudos
1 Solution

Accepted Solutions
MeleKoneya
Frequent Contributor
Here is what I ended up doing.  

var layers = dojo.map(results, function (result) {                     var layer = result.layer;                     var fields = layer.fields;                     var fieldinfo = [];                     for (var n = 0; n < fields.length; n++) {                         var field = fields;                         if (field.name == 'Asset_ID') {                             var obj = {                                 fieldName: field.name,                                 isEditable: false                             }                         }                         else {                             var obj = {                                 fieldName: field.name,                                 isEditable: true                             }                         }                         fieldinfo.push(obj);                     }                      return {                          'featureLayer': layer,                         'fieldInfos': fieldinfo                     }                 });   var attInsp = new esri.dijit.AttributeInspector({                                        layerInfos: layers                  }, 'attr');

View solution in original post

0 Kudos
1 Reply
MeleKoneya
Frequent Contributor
Here is what I ended up doing.  

var layers = dojo.map(results, function (result) {                     var layer = result.layer;                     var fields = layer.fields;                     var fieldinfo = [];                     for (var n = 0; n < fields.length; n++) {                         var field = fields;                         if (field.name == 'Asset_ID') {                             var obj = {                                 fieldName: field.name,                                 isEditable: false                             }                         }                         else {                             var obj = {                                 fieldName: field.name,                                 isEditable: true                             }                         }                         fieldinfo.push(obj);                     }                      return {                          'featureLayer': layer,                         'fieldInfos': fieldinfo                     }                 });   var attInsp = new esri.dijit.AttributeInspector({                                        layerInfos: layers                  }, 'attr');
0 Kudos