require(["esri/widgets/FeatureForm"], function(FeatureForm) { /* code goes here */ });
Class: esri/widgets/FeatureForm
Inheritance: FeatureForm Widget Accessor
Since: ArcGIS API for JavaScript 4.9

The FeatureForm widget displays attributes of a feature. This widget renders input fields based on the feature's attributes and whether the field allows editing. You can configure field groupings to aid in display and organization of form data. Use this widget, in combination with FeatureLayer.applyEdits, to enable an end user to update a feature's attribute on a specified editable feature layer(s).

featureForm

Known Limitations

The FeatureForm widget is not yet at full parity with the functionality provided in the 3.x AttributeInspector widget. For example, there is currently no support for editing attachments or related feature attributes. Although, editing attachments is possible using the Editor widget.

For information about gaining full control of widget styles, see the Styling topic.
See also:
Example:
const featureForm = new FeatureForm({
  container: "formDiv",
  feature: graphic,
  formTemplate: template
});

Constructors

new FeatureForm(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Example:
// Typical usage
const featureForm = new FeatureForm({
  container: "formDiv", // HTML div
  feature: graphic, // Pass in feature
  // Specify the form's template for how it is configured
  formTemplate: template
});

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
String|HTMLElement

The ID or node representing the DOM element containing the widget.

more details
more detailsWidget
String

The name of the class.

more details
more detailsAccessor
String

The description of the form.

more details
more detailsFeatureForm
Graphic

The associated feature containing the editable attributes.

more details
more detailsFeatureForm
FieldConfig[]|FieldGroupConfig[]

Array of individual or grouped field configuration objects.

more details
more detailsFeatureForm
FormTemplate

The associated template used for the form.

more details
more detailsFeatureForm
String

Defines how groups will be displayed to the user.

more details
more detailsFeatureForm
String

The unique ID assigned to the widget when the widget is created.

more details
more detailsWidget
String

The widget's default label.

more details
more detailsFeatureForm
FeatureLayer

Layer containing the editable feature attributes.

more details
more detailsFeatureForm
String

The title of the form.

more details
more detailsFeatureForm
FeatureFormViewModel

The view model for this widget.

more details
more detailsFeatureForm

Property Details

The ID or node representing the DOM element containing the widget. This property can only be set once. The following examples are all valid use cases when working with widgets.

Examples:
// Create the HTML div element programmatically at runtime and set to the widget's container
const basemapGallery = new BasemapGallery({
  view: view,
  container: document.createElement("div")
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
// Specify an already-defined HTML div element in the widget's container

const basemapGallery = new BasemapGallery({
  view: view,
  container: basemapGalleryDiv
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});

// HTML markup
<body>
  <div id="viewDiv"></div>
  <div id="basemapGalleryDiv"></div>
</body>
// Specify the widget while adding to the view's UI
const basemapGallery = new BasemapGallery({
  view: view
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
declaredClass Stringreadonly inherited

The name of the class. The declared class name is formatted as esri.folder.className.

description String
Since: ArcGIS API for JavaScript 4.16

The description of the form. If this is not set, it defaults to what is set within the FormTemplate.

This property was added at 4.16 to provide parity with the FormTemplate. The preferred way to set this property is via the form template's description property. The description property on the form or its view model will eventually be deprecated in a later release in favor of the setting it within the form template.

feature Graphic

The associated feature containing the editable attributes. A common way to access this is via the MapView or SceneView's hitTest() method.

Example:
// Check if a user clicked on an incident feature.
view.on("click", function(event) {
  view.hitTest(event).then(function(response) {
    // Display the attributes of selected incident feature in the form
    if (response.results[0].graphic && response.results[0].graphic.layer.id == "incidentsLayer") {
       formVM.feature = result.results[0].graphic
    }
  });
});
Deprecated since version 4.16. Use FieldElement and/or GroupElement instead.

Array of individual or grouped field configuration objects. This is where you specify what fields to display and how you wish to display them. It is possible to configure individual or grouped fields. For an example of individual field configurations, please refer to the Update FeatureLayer using ApplyEdits sample.

Starting with version 4.16, the preferred way to set the field or grouped field configurations is via FieldElement(s) or GroupElement(s) set within the form's template.

Currently, the field configuration settings take precedence over any FieldElement(s) that may be set within the form's template. The fieldConfigs property will be fully deprecated at a future release in favor of setting elements within the form's template.

When not set, all fields except for editor, globalID, objectID, and system maintained area and length fields will be included. Otherwise, it is up to the developer to set the right field(s) to override and display.

Examples:
// Individual field configurations without grouping
const featureForm = new FeatureForm({
  container: "formDiv",
  feature: graphic, // Pass in feature
  // Configure fields to display without grouping
  fieldConfig: [ // Autocasts as FieldConfig
    {
      name: "Incident_desc",
      label: "Description"
    },{
      name: "Incident_Address",
      label: "Contact"
   }]
});
// Grouped field configurations
const featureForm = new FeatureForm({
  container: "formDiv",
  feature: graphic,
  fieldConfig: [{ // Autocasts to FieldGroupConfig
    label: "Inspector", // Group 1
    description: "Inspector information",
    // Individual field configurations within the group
    fieldConfig: [{
      name: "inspector",
      label: "Name"
    },
    {
      name: "inspemail",
      label: "Email address"
    }]
   }, {
    label: "Business", // Group 2
    description: "Business information",
    // Individual field configurations within the group
    fieldConfig: [{
      name: "placename",
      label: "Business name"
    }, {
      name: "firstname",
      label: "First name"
    }]
  }]
});
Since: ArcGIS API for JavaScript 4.16

The associated template used for the form.

The formTemplate is where you configure how the form should display. Properties, i.e. title, description, fieldConfigs, etc, set directly within the FeatureForm take precedence over any similar properties set within the formTemplate. This will change in a future release as the preferred way to set the form's properties is via it's template.

See also:
Example:
// Create the Form template and pass in elements
const formTemplate = new FormTemplate({
  title: "Inspector report",
  description: "Enter all relevant information below",
  elements: [groupElement] // Add all elements to the template
});

// Add a new feature form with grouped fields
const form = new FeatureForm({
  container: "form",
  groupDisplay: "sequential", // only display one group at a time
  formTemplate: formTemplate // set it to template created above
});
groupDisplay String
Since: ArcGIS API for JavaScript 4.10

Defines how groups will be displayed to the user.

Possible Values

ValueDescription
allAll groups will be expanded.
sequentialA single group will be expanded at a time.

Possible Values:"all"|"sequential"

Default Value:all
See also:

The unique ID assigned to the widget when the widget is created. If not set by the developer, it will default to the container ID, or if that is not present then it will be automatically generated.

label String

The widget's default label.

Layer containing the editable feature attributes. If this layer is not specified, it is the same as the graphic's layer.

Example:
const form = new FeatureForm({
  container: "formDiv", // HTML div
  layer: featureLayer // Feature layer
});
title String
Since: ArcGIS API for JavaScript 4.16

The title of the form. If this is not set, it defaults to what is set within the FormTemplate.

This property was added at 4.16 to provide parity with the FormTemplate. The preferred way to set this property is via the form template's title property. The title property on the form or its view model will eventually be deprecated in a later release in favor of the setting it within the form template.

The view model for this widget. This is a class that contains all the logic (properties and methods) that controls this widget's behavior. See the FeatureFormViewModel class to access all properties and methods on the widget.

Method Overview

NameReturn TypeSummaryClass
String

A utility method used for building the value for a widget's class property.

more details
more detailsWidget

Destroys the widget instance.

more details
more detailsWidget
Object

Returns all of the field values, regardless of whether or not they were updated.

more details
more detailsFeatureForm
Object

Registers an event handler on the instance.

more details
more detailsWidget

Widget teardown helper.

more details
more detailsWidget

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget
Object

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

Renders widget to the DOM immediately.

more details
more detailsWidget

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

Fires the submit event.

more details
more detailsFeatureForm

Method Details

classes(classNames){String}inherited

A utility method used for building the value for a widget's class property. This aids in simplifying CSS class setup.

Parameter:
repeatable

The class names.

Returns:
TypeDescription
StringThe computed class name.
See also:
Example:
// .tsx syntax showing how to set CSS classes while rendering the widget

render() {
  const dynamicIconClasses = {
    [CSS.myIcon]: this.showIcon,
    [CSS.greyIcon]: !this.showIcon
  };

  return (
    <div class={classes(CSS.root, CSS.mixin, dynamicIconClasses)} />
  );
}
destroy()inherited

Destroys the widget instance.

getValues(){Object}

Returns all of the field values, regardless of whether or not they were updated.

Returns:
TypeDescription
ObjectAn object of key-value pairs of field names with their values.
See also:
Example:
function updateFeature() {
  // Get the updated field values
  const attributes = form.getValues();
  // Call applyEdits on the featurelayer
  layer.applyEdits({
    // Pass in the updated field values
    updateFeatures: [{ attributes }]
  });
}
on(type, listener){Object}inherited

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters:

A event type, or an array of event types, to listen for.

listener Function

The function to call when the event is fired.

Returns:
TypeDescription
ObjectReturns an event handler with a remove() method that can be called to stop listening for the event(s).
PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example:
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});
own(handles)inherited

Widget teardown helper. Any handles added to it will be automatically removed when the widget is destroyed.

Parameter:

Handles marked for removal once the widget is destroyed.

postInitialize()inherited

This method is primarily used by developers when implementing custom widgets. Executes after widget is ready for rendering.

render(){Object}inherited

This method is primarily used by developers when implementing custom widgets. It must be implemented by subclasses for rendering.

Returns:
TypeDescription
ObjectThe rendered virtual node.
renderNow()inherited

Renders widget to the DOM immediately.

scheduleRender()inherited

This method is primarily used by developers when implementing custom widgets. Schedules widget rendering. This method is useful for changes affecting the UI.

submit()

Fires the submit event.

Example:
// Listen for when 'submit' is called on the FeatureForm.
// Once it is fired, update the feature.
form.on("submit", updateFeature);
// When the DOM's button (btnUpdate) is clicked,
// execute the 'submit()' method.
on(dom.byId("btnUpdate"), "click", form.submit());

Event Overview

NameTypeSummaryClass
{valid: String[],invalid: String[],values: Object}

Fires when the submit() method is called.

more details
more detailsFeatureForm
{layer: FeatureLayer,feature: Graphic,fieldName: String,value: Number,String,null,valid: Boolean}

Fires when a field value is updated.

more details
more detailsFeatureForm

Event Details

submit

Fires when the submit() method is called. Call FeatureLayer.applyEdits() method to update a feature's attributes.

Properties:
valid String[]

The valid field names.

invalid String[]

The invalid field names.

values Object

An object of key-value pairs of field names with all of their values, regardless of whether or not they were updated.

See also:
Example:
// Listen to the feature form's submit event.
featureForm.on("submit", function(){
  if (editFeature) {
    // Grab updated attributes from the form.
    const updated = featureForm.getValues();

    // Loop through updated attributes and assign
    // the updated values to feature attributes.
    Object.keys(updated).forEach(function(name) {
      editFeature.attributes[name] = updated[name];
    });

    // Setup the applyEdits parameter with updates.
    const edits = {
      updateFeatures: [editFeature]
    };
    applyEdits(edits);
  }
});
value-change

Fires when a field value is updated.

Properties:

The associated feature layer.

feature Graphic

The associated feature.

fieldName String

The updated field.

The updated field value.

valid Boolean

When true, the value conforms to the field's definition.

API Reference search results

NameTypeModule
Loading...