Select to view content in your preferred language

Attribute Inspector not Updating Features - Anything to do with the proxy page?

1821
8
Jump to solution
10-04-2013 12:33 PM
ionarawilson1
Deactivated User
Does anybody know why the Attribute Inspector does not save the changes? I have used my own data and the example data and both don't work. Do I need to add something to the proxy page perhaps? Thank you!

<!DOCTYPE html> <html>    <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">     <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">     <!--The viewport meta tag is used to improve the presentation and behavior of the samples        on iOS devices-->     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">     <title>Editable FeatureLayer in Selection Only Mode with Attribute Inspector</title>      <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/dojo/dijit/themes/claro/claro.css">     <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css" />     <style>       html, body {          height: 100%; width: 100%;          margin: 0;         padding: 0;         overflow: hidden;       }       #mapDiv{         margin: 0;         padding:0;       }       #detailPane{         height:20px;         color:#570026;         font-size:12pt;         font-weight:600;         overflow:hidden;       }       .dj_ie .infowindow .window .top .right .user .content { position: relative; }       .dj_ie .simpleInfoWindow .content {position: relative;}        .esriAttributeInspector {height:100px;}       .esriAttributeInspector .atiLayerName {display:none;}       .saveButton {         padding-left:45px;          margin:0px;width:16px; height:16px;        }     </style>          <script src="http://js.arcgis.com/3.7/"></script>     <script>       var map;       var updateFeature;              require([         "esri/map",         "esri/layers/FeatureLayer",         "esri/dijit/AttributeInspector",          "esri/symbols/SimpleLineSymbol",         "esri/symbols/SimpleFillSymbol",         "dojo/_base/Color",          "esri/layers/ArcGISDynamicMapServiceLayer",         "esri/config",          "esri/tasks/query",          "dojo/parser",          "dojo/dom-construct",         "dijit/form/Button",          "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"       ], function(         Map, FeatureLayer, AttributeInspector,         SimpleLineSymbol, SimpleFillSymbol, Color,         ArcGISDynamicMapServiceLayer, esriConfig,         Query,         parser, domConstruct, Button       ) {         parser.parse();          // refer to "Using the Proxy Page" for more information:  https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html         esriConfig.defaults.io.proxyUrl = "/proxy";          map = new Map("mapDiv", {                basemap: "hybrid",                     center: [-98.57, 30.98],           zoom: 6,           slider: true          });                  map.on("layers-add-result", initSelectToolbar);          var petroFieldsMSL = new ArcGISDynamicMapServiceLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/MapServer");         petroFieldsMSL.setDisableClientCaching(true);         map.addLayer(petroFieldsMSL);          var petroFieldsFL = new FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/FeatureServer/2", {           mode: FeatureLayer.MODE_SELECTION,           outFields: ["Office", "Forester"]         });         var selectionSymbol = new SimpleFillSymbol(           SimpleFillSymbol.STYLE_NULL,            new SimpleLineSymbol(             "solid",              new Color("yellow"),              2           ),           null         );         petroFieldsFL.setSelectionSymbol(selectionSymbol);          petroFieldsFL.on("edits-complete", function() {           petroFieldsMSL.refresh();         });          map.addLayers([petroFieldsFL]);          function initSelectToolbar(evt) {           var petroFieldsFL = evt.layers[0].layer;           var selectQuery = new Query();            map.on("click", function(evt) {             selectQuery.geometry = evt.mapPoint;             petroFieldsFL.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW, function(features) {               if (features.length > 0) {                //store the current feature                 updateFeature = features[0];                 map.infoWindow.setTitle(features[0].getLayer().name);                 map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));               } else {                 map.infoWindow.hide();               }             });           });            map.infoWindow.on("hide", function() {             petroFieldsFL.clearSelection();           });            var layerInfos = [{             'featureLayer': petroFieldsFL,             'showAttachments': false,             'isEditable': true,             'fieldInfos': [               {'fieldName': 'Office', 'isEditable':true, 'tooltip': 'Office', 'label':'Office:'},               {'fieldName': 'Forester', 'isEditable':true, 'tooltip': 'Forester', 'label':'Forester:'}             ]           }];            var attInspector = new AttributeInspector({             layerInfos:layerInfos           }, domConstruct.create("div"));                      //add a save button next to the delete button           var saveButton = new Button({ label: "Save", "class": "saveButton"});           domConstruct.place(saveButton.domNode, attInspector.deleteBtn.domNode, "after");                     saveButton.on("click", function(){             updateFeature.getLayer().applyEdits(null, [updateFeature], null);                    });                      attInspector.on("attribute-change", function(evt) {             //store the updates to apply when the save button is clicked               updateFeature.attributes[evt.fieldName] = evt.newFieldValue;           });                      attInspector.on("next", function(evt) {             updateFeature = evt.feature;             console.log("Next " + updateFeature.attributes.objectid);           });                      attInspector.on("delete", function(evt){             evt.feature.getLayer().applyEdits(null,null,[feature]);             map.infoWindow.hide();           });            map.infoWindow.setContent(attInspector.domNode);           map.infoWindow.resize(350, 240);         }       });     </script>   </head>      <body class="claro">     <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%;height:100%;">       <div id="detailPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'">         Click a field to display the attribute inspector with customized fields.       </div>       <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'" id="mapDiv"></div>     </div>   </body> </html>
0 Kudos
1 Solution

Accepted Solutions
ThomasRoussell
Regular Contributor
This code works for me. You will have to change my server, featurelayer and fieldinfos to match your data.

<!DOCTYPE html> <html>    <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">     <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">     <!--The viewport meta tag is used to improve the presentation and behavior of the samples        on iOS devices-->     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">     <title>Editable FeatureLayer in Selection Only Mode with Attribute Inspector</title>      <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/dojo/dijit/themes/claro/claro.css"/>     <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css"/>    <style>       html, body {          height: 98%; width: 98%;          padding: 0;         overflow:hidden;       }       #mapDiv{         padding:0;         border: solid 2px #705B35;       }       .roundedCorners {         -moz-border-radius: 4px;         border-radius: 4px;       }       #detailPane{         height:20px;         color:#570026;         font-size:12pt;         font-weight:600;         overflow:hidden;       }       .dj_ie .infowindow .window .top .right .user .content { position: relative; }       .dj_ie .simpleInfoWindow .content {position: relative;}        .esriAttributeInspector {height:100px;}       .esriAttributeInspector .atiLayerName {display:none;}       .saveButton {         padding-left:45px;          margin:0px;width:16px; height:16px;        }     </style>          <script>var dojoConfig = { parseOnLoad: true };</script>     <script src="http://js.arcgis.com/3.7/"></script>     <script>         dojo.require("dijit.layout.BorderContainer");         dojo.require("dijit.layout.ContentPane");         dojo.require("esri.map");         dojo.require("esri.dijit.AttributeInspector-all");          var map;         var updateFeature;          function init() {             //This works without the proxy page.              //esri.config.defaults.io.proxyUrl = "http://myserver/proxy/proxy.ashx";             //esri.config.defaults.io.proxyUrl = "/proxy";              map = new esri.Map("mapDiv", {                 basemap: "streets",                 center: [-68, 47.5],                 zoom: 5             });              dojo.connect(map, "onLayersAddResult", initSelectToolbar);              var petroFieldsMSL = new esri.layers.ArcGISDynamicMapServiceLayer("http://myserver:6080/arcgis/rest/services/HB2012_Edit/Mapserver/");             petroFieldsMSL.setDisableClientCaching(true);             map.addLayer(petroFieldsMSL);              var petroFieldsFL = new esri.layers.FeatureLayer("http://myserver:6080/arcgis/rest/services/HB2012_Edit/FeatureServer/0", {                 mode: esri.layers.FeatureLayer.MODE_SELECTION,                 outFields: ["*"]             });             var selectionSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color("yellow"), 2), null);             petroFieldsFL.setSelectionSymbol(selectionSymbol);              dojo.connect(petroFieldsFL, "onEditsComplete", function () {                 petroFieldsMSL.refresh();             });              map.addLayers([petroFieldsFL]);         }          function initSelectToolbar(results) {             var petroFieldsFL = results[0].layer;             var selectQuery = new esri.tasks.Query();              dojo.connect(map, "onClick", function (evt) {                 selectQuery.geometry = evt.mapPoint;                 petroFieldsFL.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {                     if (features.length > 0) {                         //store the current feature                         updateFeature = features[0];                         map.infoWindow.setTitle(features[0].getLayer().name);                         map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));                     } else {                         map.infoWindow.hide();                     }                 });             });              dojo.connect(map.infoWindow, "onHide", function () {                 petroFieldsFL.clearSelection();             });              var fieldinfos = new Array();             fieldinfos.push({ 'fieldName': 'ATCOMMENT', 'isEditable': true, 'label': 'AT COMMENT:', 'stringFieldOption': esri.dijit.AttributeInspector.STRING_FIELD_OPTION_TEXTAREA });             fieldinfos.push({ 'fieldName': 'Last_Modified_By', 'isEditable': false, 'label': 'Last Modified By:' });             fieldinfos.push({ 'fieldName': 'Last_Modified_Date', 'isEditable': false, 'label': 'Last Modified Date:' });              var layerInfos = [{                 'featureLayer': petroFieldsFL,                 'showAttachments': false,                 'isEditable': true,                 'fieldInfos': fieldinfos             }];              var attInspector = new esri.dijit.AttributeInspector({                 layerInfos: layerInfos             }, dojo.create("div"));              //add a save button next to the delete button             var saveButton = new dijit.form.Button({ label: "Save", "class": "saveButton" });             dojo.place(saveButton.domNode, attInspector.deleteBtn.domNode, "after");              dojo.connect(saveButton, "onClick", function () {                 updateFeature.getLayer().applyEdits(null, [updateFeature], null);             });              dojo.connect(attInspector, "onAttributeChange", function (feature, fieldName, newFieldValue) {                 //store the updates to apply when the save button is clicked                  updateFeature.attributes[fieldName] = newFieldValue;             });              dojo.connect(attInspector, "onNext", function (feature) {                 updateFeature = feature;                 console.log("Next " + updateFeature.attributes.objectid);             });              dojo.connect(attInspector, "onDelete", function (feature) {                 feature.getLayer().applyEdits(null, null, [feature]);                 map.infoWindow.hide();             });              map.infoWindow.setContent(attInspector.domNode);             map.infoWindow.resize(325, 220);         }          dojo.ready(init);     </script>   </head>      <body class="claro">     <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%;height:100%;">       <div id="detailPane" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">         Click a field to display the attribute inspector with customized fields.       </div>       <div data-dojo-type="dijit.layout.ContentPane" class="roundedCorners" data-dojo-props="region:'center'" id="mapDiv"></div>     </div>   </body> </html>

View solution in original post

0 Kudos
8 Replies
ThomasRoussell
Regular Contributor
I noticed this when I tried to change to AMD model. When I used the legacy dojo.require it worked fine.
0 Kudos
ionarawilson1
Deactivated User
So what would be the option?
0 Kudos
ThomasRoussell
Regular Contributor
I would try changing

      require([
        "esri/map",
        "esri/layers/FeatureLayer",
        "esri/dijit/AttributeInspector", ...



to the old format and see if that works:

    dojo.require("esri.map");
    dojo.require("esri.layers.FeatureLayer");
    dojo.require("esri/dijit/AttributeInspector"); ...

    function init() {...

    dojo.ready(init);
    </script>

0 Kudos
ionarawilson1
Deactivated User
I tried one sample with that and it is also not working. Do you have any examples that work? Thanks
0 Kudos
ThomasRoussell
Regular Contributor
This code works for me. You will have to change my server, featurelayer and fieldinfos to match your data.

<!DOCTYPE html> <html>    <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">     <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">     <!--The viewport meta tag is used to improve the presentation and behavior of the samples        on iOS devices-->     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">     <title>Editable FeatureLayer in Selection Only Mode with Attribute Inspector</title>      <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/dojo/dijit/themes/claro/claro.css"/>     <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css"/>    <style>       html, body {          height: 98%; width: 98%;          padding: 0;         overflow:hidden;       }       #mapDiv{         padding:0;         border: solid 2px #705B35;       }       .roundedCorners {         -moz-border-radius: 4px;         border-radius: 4px;       }       #detailPane{         height:20px;         color:#570026;         font-size:12pt;         font-weight:600;         overflow:hidden;       }       .dj_ie .infowindow .window .top .right .user .content { position: relative; }       .dj_ie .simpleInfoWindow .content {position: relative;}        .esriAttributeInspector {height:100px;}       .esriAttributeInspector .atiLayerName {display:none;}       .saveButton {         padding-left:45px;          margin:0px;width:16px; height:16px;        }     </style>          <script>var dojoConfig = { parseOnLoad: true };</script>     <script src="http://js.arcgis.com/3.7/"></script>     <script>         dojo.require("dijit.layout.BorderContainer");         dojo.require("dijit.layout.ContentPane");         dojo.require("esri.map");         dojo.require("esri.dijit.AttributeInspector-all");          var map;         var updateFeature;          function init() {             //This works without the proxy page.              //esri.config.defaults.io.proxyUrl = "http://myserver/proxy/proxy.ashx";             //esri.config.defaults.io.proxyUrl = "/proxy";              map = new esri.Map("mapDiv", {                 basemap: "streets",                 center: [-68, 47.5],                 zoom: 5             });              dojo.connect(map, "onLayersAddResult", initSelectToolbar);              var petroFieldsMSL = new esri.layers.ArcGISDynamicMapServiceLayer("http://myserver:6080/arcgis/rest/services/HB2012_Edit/Mapserver/");             petroFieldsMSL.setDisableClientCaching(true);             map.addLayer(petroFieldsMSL);              var petroFieldsFL = new esri.layers.FeatureLayer("http://myserver:6080/arcgis/rest/services/HB2012_Edit/FeatureServer/0", {                 mode: esri.layers.FeatureLayer.MODE_SELECTION,                 outFields: ["*"]             });             var selectionSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color("yellow"), 2), null);             petroFieldsFL.setSelectionSymbol(selectionSymbol);              dojo.connect(petroFieldsFL, "onEditsComplete", function () {                 petroFieldsMSL.refresh();             });              map.addLayers([petroFieldsFL]);         }          function initSelectToolbar(results) {             var petroFieldsFL = results[0].layer;             var selectQuery = new esri.tasks.Query();              dojo.connect(map, "onClick", function (evt) {                 selectQuery.geometry = evt.mapPoint;                 petroFieldsFL.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {                     if (features.length > 0) {                         //store the current feature                         updateFeature = features[0];                         map.infoWindow.setTitle(features[0].getLayer().name);                         map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));                     } else {                         map.infoWindow.hide();                     }                 });             });              dojo.connect(map.infoWindow, "onHide", function () {                 petroFieldsFL.clearSelection();             });              var fieldinfos = new Array();             fieldinfos.push({ 'fieldName': 'ATCOMMENT', 'isEditable': true, 'label': 'AT COMMENT:', 'stringFieldOption': esri.dijit.AttributeInspector.STRING_FIELD_OPTION_TEXTAREA });             fieldinfos.push({ 'fieldName': 'Last_Modified_By', 'isEditable': false, 'label': 'Last Modified By:' });             fieldinfos.push({ 'fieldName': 'Last_Modified_Date', 'isEditable': false, 'label': 'Last Modified Date:' });              var layerInfos = [{                 'featureLayer': petroFieldsFL,                 'showAttachments': false,                 'isEditable': true,                 'fieldInfos': fieldinfos             }];              var attInspector = new esri.dijit.AttributeInspector({                 layerInfos: layerInfos             }, dojo.create("div"));              //add a save button next to the delete button             var saveButton = new dijit.form.Button({ label: "Save", "class": "saveButton" });             dojo.place(saveButton.domNode, attInspector.deleteBtn.domNode, "after");              dojo.connect(saveButton, "onClick", function () {                 updateFeature.getLayer().applyEdits(null, [updateFeature], null);             });              dojo.connect(attInspector, "onAttributeChange", function (feature, fieldName, newFieldValue) {                 //store the updates to apply when the save button is clicked                  updateFeature.attributes[fieldName] = newFieldValue;             });              dojo.connect(attInspector, "onNext", function (feature) {                 updateFeature = feature;                 console.log("Next " + updateFeature.attributes.objectid);             });              dojo.connect(attInspector, "onDelete", function (feature) {                 feature.getLayer().applyEdits(null, null, [feature]);                 map.infoWindow.hide();             });              map.infoWindow.setContent(attInspector.domNode);             map.infoWindow.resize(325, 220);         }          dojo.ready(init);     </script>   </head>      <body class="claro">     <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%;height:100%;">       <div id="detailPane" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">         Click a field to display the attribute inspector with customized fields.       </div>       <div data-dojo-type="dijit.layout.ContentPane" class="roundedCorners" data-dojo-props="region:'center'" id="mapDiv"></div>     </div>   </body> </html>
0 Kudos
ionarawilson1
Deactivated User
Thanks a lot Thomas!
0 Kudos
ThomasRoussell
Regular Contributor
You're Welcome. Hopefully ESRI will find the problem with the new AMD model soon. I am just getting started with JavaScript and I would like to switch to the new format before I create a lot of code in the old format.
0 Kudos
RayGreen
Emerging Contributor
Thomas I copied your code and made the changes needed, but for some reason it still doesn't update the data.  Does anyone know if this has to do with my services being https and not using a designated port?
0 Kudos