Show the attribute inspector without saving a new feature

452 views Asked by At

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 :

      dojo.connect(drawToolbar, "onDrawEnd", function(geometry) {  
          //display the editable info window for newly created features  

      if (map.infoWindow.isShowing) {  
        map.infoWindow.hide();  
      }  

      drawToolbar.deactivate();  

      var fieldAttributes = layerFieldToAttributes(selectedTemplate.featureLayer.fields);  
      var newAttributes = dojo.mixin(fieldAttributes, selectedTemplate.template.prototype.attributes);  
      var newGraphic = new esri.Graphic(geometry, null, newAttributes);  

      var layerInfos = [{  
        'featureLayer': selectedTemplate.featureLayer,  
        'isEditable': true  
      }];  

      var attInspector = new esri.dijit.AttributeInspector({  
        layerInfos: layerInfos  
      }, dojo.create("div"));  

      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();  
      });  

      dojo.connect(attInspector, "onAttributeChange", function(feature, fieldName, newFieldValue) {  
        feature.attributes[fieldName] = newFieldValue;  
        feature.getLayer().applyEdits(null, [feature], null);  
      });  

      dojo.connect(attInspector, "onDelete", function(feature) {  
        feature.getLayer().applyEdits(null, null, [feature]);  
        map.infoWindow.hide();  
      });  
    });  
  }  

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

Any help would be appreciated.

Here is the sample project : https://www.dropbox.com/s/fh71g1k9nsa70nq/index-2.html.zip?dl=0

1

There are 1 answers

0
Reza On

I dont think you can do that with the AttributeInspector, try creating a custom popup that will have options to save and delete/cancel, when saving fire the applyEdits, when clicking delete, remove, ect.

Content:

var content = "<input id='text1'></input> </br>" +
                "<input id='text1'></input> </br>" + "<button id='submit'>Submit</button>" + "<button id='delete'>Delete</button>"
                /*
                var attInspector = new AttributeInspector({
                    layerInfos: layerInfos
                }, dojo.create("div"));
                */
                map.infoWindow.setTitle(selectedTemplate.featureLayer.name);
                map.infoWindow.setContent(content);
                map.infoWindow.resize(350, 240);

                map.infoWindow.show(evt.geometry, map.getInfoWindowAnchor(evt.geometry));

Listener:

on(map.infoWindow, "show", function () {
            on(dom.byId("submit"), "click", function () {
                alert("I should be saving");
            });
            on(dom.byId("delete"), "click", function () {
                alert("I should be deleting");
            });
        })

Check out this fiddler: https://jsfiddle.net/kreza/jpLj5y4h/2/