Show the attribute inspector without saving a new feature

2033
7
12-29-2016 01:16 AM
ozcandurak
New Contributor III

Hi,

The requirement is to add a new feature from template picker but without applying it, can i show the attribute inspector than save the feature.

selectedTemplate = templatePicker.getSelected();

This selectedTemplate is then selected to put the points on the map than opens the attribute inspector by selecting it.

selectedTemplate.featureLayer.applyEdits([newGraphic], null, null);

Sample Code Block :

  1.  dojo.connect(drawToolbar, "onDrawEnd", function(geometry) {  
  2.           //display the editable info window for newly created features  
  3.           
  4.           if (map.infoWindow.isShowing) {  
  5.             map.infoWindow.hide();  
  6.           }  
  7.   
  8.           drawToolbar.deactivate();  
  9.   
  10.           var fieldAttributes = layerFieldToAttributes(selectedTemplate.featureLayer.fields);  
  11.           var newAttributes = dojo.mixin(fieldAttributes, selectedTemplate.template.prototype.attributes);  
  12.           var newGraphic = new esri.Graphic(geometry, null, newAttributes);  
  13.   
  14.           var layerInfos = [{  
  15.             'featureLayer': selectedTemplate.featureLayer,  
  16.             'isEditable': true  
  17.           }];  
  18.   
  19.           var attInspector = new esri.dijit.AttributeInspector({  
  20.             layerInfos: layerInfos  
  21.           }, dojo.create("div"));  
  22.   
  23.           selectedTemplate.featureLayer.applyEdits([newGraphic], null, null, function() {  
  24.             var screenPoint = map.toScreen(getInfoWindowPositionPoint(newGraphic));  
  25.               
  26.             map.infoWindow.setContent(attInspector.domNode);  
  27.             map.infoWindow.resize(325, 185);  
  28.             map.infoWindow.show(screenPoint, map.getInfoWindowAnchor(screenPoint));  
  29.   
  30.             templatePicker.clearSelection();  
  31.           });  
  32.   
  33.           dojo.connect(attInspector, "onAttributeChange", function(feature, fieldName, newFieldValue) {  
  34.             feature.attributes[fieldName] = newFieldValue;  
  35.             feature.getLayer().applyEdits(null, [feature], null);  
  36.           });  
  37.   
  38.           dojo.connect(attInspector, "onDelete", function(feature) {  
  39.             feature.getLayer().applyEdits(null, null, [feature]);  
  40.             map.infoWindow.hide();  
  41.           });  
  42.         });  
  43.       }  

I would like my client first add the attribute to feature and (save & apply) it.

Any help would be appreciated. 

0 Kudos
7 Replies
ozcandurak
New Contributor III
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ozcan,

  These lines are what create the feature in the feature layer:

          selectedTemplate.featureLayer.applyEdits([newGraphic], null, null, function() {
            var screenPoint = map.toScreen(getInfoWindowPositionPoint(newGraphic));
            
            map.infoWindow.setContent(attInspector.domNode);
            map.infoWindow.resize(325, 185);
            map.infoWindow.show(screenPoint, map.getInfoWindowAnchor(screenPoint));

            templatePicker.clearSelection();
          });

So just call all the code (lines 2 - 😎 without lines 1 and 9 and then once you add a save button to your Attribute Inspector then you can:

selectedTemplate.featureLayer.applyEdits([newGraphic], null, null);

here is a thread showing how to add the save button to the Attribute Inspector:

https://community.esri.com/thread/171824 

ozcandurak
New Contributor III

Hi Robert,

Thanks for the reply.

My question is not to open the attribute inspector after applying the edits. I would like to first create the feature on map and open the attribue inspector, once all my fields has been filled than i would like to apply and send it to server.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

That is exactly what I understood and advised in my last reply.

0 Kudos
ozcandurak
New Contributor III

Hi rscheitlin,

Here is the sample i have tried, Dropbox - index-2.html.zip 

Please have look at it.

Regards.

0 Kudos
ozcandurak
New Contributor III

Hi Robert,

I have tried many times, but had no success,

the attribute inspector is opening but there isn't any content contains. When creating a feature from templatePicker the feature has no objectId yet, therefore until i save i cannot get objectId and cannot use selectFeature. My aim is to save the data to server after i finish with it attributes.

Can you please share a sample if possible. 

Best Regards.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ozcan,

   The OID will not get assigned until you save the feature to the FeatureService. A selectFeature call can not be used until the feature service has a feature back on the server. You should be able to do all you attribute working in the attribute inspector and then once you are done applying your attributes you use layer.applyEdits([graphic], null, null); to save it to the service.