Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />

  <!--  <link rel="stylesheet" href="https://js.arcgis.com/next/esri/themes/light/main.css">
  <script src="https://js.arcgis.com/next/"></script>
  -->

   <link href="https://js.arcgis.com/4.23/esri/themes/light/main.css" rel="stylesheet" type="text/css" />
   <script src="https://js.arcgis.com/4.23/" type="text/javascript"></script>

  <style>
    html,
    body,
    #viewDiv {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }

    #info {
      padding: 14px;
      border-radius: 5px;
    }

    #update {
      padding: 6px;
    }

    #edit-form {
      background: #fff;
    }

    /* replaces esri-widget--panel */
    .scroller {
      overflow-x: hidden;
      overflow-y: auto;
    }

    .dtcontainer {
      display: flex;
      height: 100%
    }

    .dtcontainer .esri-date-picker,
    .dtcontainer .esri-time-picker {
      flex: 1 1 0%;
      /* border-top: 0;*/
    }

    .dtcontainer .esri-time-picker {
      padding: 0;
      display: flex;
      justify-content: center;
    }
  </style>

  <script>
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/widgets/FeatureForm",
      "esri/layers/FeatureLayer",
      "esri/form/FormTemplate",
      "esri/form/elements/inputs/DateTimePickerInput",
      "esri/widgets/support/DatePicker",
      "esri/widgets/support/TimePicker"
    ], (Map, MapView, FeatureForm, FeatureLayer, FormTemplate, DateTimePickerInput, DatePicker, TimePicker) => {
      let highlight, editFeature;
      const dateTimePicker = new DateTimePickerInput({
        includeTime: false, // this will allow time input, default is false
      });
       const featureLayer = new FeatureLayer({
        url: "https://ddotgis.dc.gov/arcgis/rest/services/Test/TestPoint/FeatureServer/0",
        outFields: ["*"]
      });
      const map = new Map({
        basemap: "gray-vector",
        layers: [featureLayer]
      });
      const view = new MapView({
        map: map,
        container: "viewDiv",
        center: [-77.036, 38.903],
        zoom: 14,
        popup: {
          autoOpenEnabled: false
        }
      });
      // Add a new feature form with grouped fields
      const form = new FeatureForm({
        container: "edit-form",
        groupDisplay: "sequential", // only display one group at a time
        layer: featureLayer,
        formTemplate: { // Autocasts to new FormTemplate
          title: "Edit",
          description: "",
          elements: [{
            type: "field",
            fieldName: "WorkType",
            label: "Work Type"
          }, {
            type: "field",
            fieldName: "ProjectStatus",
            label: "Status"
          },{
            type: "field",
            fieldName: "EstimatedCost",
            label: "Cost",
          },{
            type: "field",
            fieldName: "StartDate",
            label: "Start Date",
            input: {
              type: "datetime-picker"
            }
          }, {
            type: "field",
            fieldName: "EndDate",
            label: "End Date",
            input: {
              type: "datetime-picker"
            }
          }]
        }
      });
      console.log(form.formTemplate)
      
      view.on("click", (event) => {
        // Unselect any currently selected features
        unselectFeature();
        // 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;
          if (
            results.length > 0 &&
            results[0].graphic &&
            results[0].graphic.layer === featureLayer
          ) {
            selectFeature(
              results[0].graphic.attributes[featureLayer.objectIdField]
            );
          } else {
            // Hide the form and show the info div
            document.getElementById("update").classList.add("esri-hidden");
          }
        });
      });
      // Function to unselect features
      function unselectFeature() {
        if (highlight) {
          highlight.remove();
        }
      }
      // Highlight the clicked feature and display
      // its attributes in the featureform.
      function selectFeature(objectId) {
        // query feature from the server
        featureLayer
          .queryFeatures({
            objectIds: [objectId],
            outFields: ["*"],
            returnGeometry: true
          })
          .then((results) => {
            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", () => {
        if (editFeature) {
          // 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.
          const edits = {
            updateFeatures: [editFeature]
          };
          applyAttributeUpdates(edits);
        }
      });
      // Call FeatureLayer.applyEdits() with specified params.
      function applyAttributeUpdates(params) {
        document.getElementById("btnUpdate").style.cursor = "progress";
        featureLayer
          .applyEdits(params)
          .then((editsResult) => {
            // 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;
              selectFeature(objectId);
            }
            document.getElementById("btnUpdate").style.cursor = "pointer";
          })
          .catch((error) => {
            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.
        form.submit();
      };
      view.ui.add("update", "top-right");
      view.ui.add("info", {
        position: "top-left",
        index: 1
      });
    });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
  <div id="info" class="esri-widget">
    <h3>Select a feature to begin editing</h3>
  </div>

  <div id="update" class="esri-widget esri-hidden">
    <div id="edit-form" class="scroller esri-component"></div>
    <input type="button" class="esri-button" value="Update" id="btnUpdate" />
  </div>
</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console