<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Update Feature Attributes | Sample | ArcGIS Maps SDK for JavaScript</title>
<link rel="stylesheet" href="https://js.arcgis.com/5.0/esri/themes/light/main.css" />
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
/* replaces esri-widget--panel */
const [Map, MapView, FeatureForm, FeatureLayer, FormTemplate] = await $arcgis.import([
"@arcgis/core/views/MapView.js",
"@arcgis/core/widgets/FeatureForm.js",
"@arcgis/core/layers/FeatureLayer.js",
"@arcgis/core/form/FormTemplate.js",
let highlight, editFeature;
const featureLayer = new FeatureLayer({
id: "449887ea7d60429fbf6f0c67881f2758",
// Autocasts to new FormTemplate
title: "Damage assessments",
description: "Provide information for insurance",
// Autocasts to new GroupElement
label: "Inspector Information",
description: "Field inspector information",
// Autocasts to new FieldElement
visibilityExpression: "alwaysHidden",
label: "Date of inspection",
}, // end of first group element
label: "Contact information",
description: "The insured's contact information",
label: "Work telephone number",
}, // end of second group element
label: "Insurance coverage",
description: "Structure and contents coverage",
label: "Structure insured",
label: "Contents insured",
}, // end of third group element
label: "Insurance type information",
description: "Type of insurance coverage",
}, // end of fourth group element
}, // end of form template elements
const view = new MapView({
center: [-88.143, 41.774],
// Add a new feature form with grouped fields
const form = new FeatureForm({
map: map, // required if using Arcade expressions using the $map global variable
groupDisplay: "sequential", // only display one group at a time
view.on("click", (event) => {
// Unselect any currently selected features
// Listen for when the user clicks on the view
view.hitTest(event).then((response) => {
// If user selects a feature, select it
const results = response.results;
results[0].graphic.layer === featureLayer
selectFeature(response.results[0].graphic.getObjectId());
// Hide the form and show the info div
document.getElementById("update").classList.add("esri-hidden");
// Function to unselect features
function unselectFeature() {
// Highlight the clicked feature and display
// its attributes in the featureform.
function selectFeature(objectId) {
// query feature from the server
if (results.features.length > 0) {
editFeature = results.features[0];
// display the attributes of selected feature in the form
form.feature = editFeature;
// highlight the feature on the view
view.whenLayerView(editFeature.layer).then((layerView) => {
highlight = layerView.highlight(editFeature);
if (document.getElementById("update").classList.contains("esri-hidden")) {
document.getElementById("info").classList.add("esri-hidden");
document.getElementById("update").classList.remove("esri-hidden");
// Listen to the feature form's submit event.
form.on("submit", () => {
// Grab updated attributes from the form.
const updated = form.getValues();
// Loop through updated attributes and assign
// the updated values to feature attributes.
Object.keys(updated).forEach((name) => {
editFeature.attributes[name] = updated[name];
// Setup the applyEdits parameter with updates.
updateFeatures: [editFeature],
applyAttributeUpdates(edits);
// Call FeatureLayer.applyEdits() with specified params.
function applyAttributeUpdates(params) {
document.getElementById("btnUpdate").style.cursor = "progress";
// Get the objectId of the newly added feature.
// Call selectFeature function to highlight the new feature.
if (editsResult.addFeatureResults.length > 0) {
const objectId = editsResult.addFeatureResults[0].objectId;
document.getElementById("btnUpdate").style.cursor = "pointer";
console.log("===============================================");
console.error("[ applyEdits ] FAILURE: ", error.code, error.name, error.message);
console.log("error = ", error);
document.getElementById("btnUpdate").style.cursor = "pointer";
document.getElementById("btnUpdate").onclick = () => {
// Fires feature form's submit event.
view.ui.add("update", "top-right");
<div id="info" class="esri-widget">
<h3>Select a feature to begin editing</h3>
<div id="update" class="esri-widget esri-hidden">
<div id="form" class="scroller esri-component"></div>
<input type="button" class="esri-button" value="Update assessment" id="btnUpdate" />