FeatureFormViewModel

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

Provides the logic for the FeatureForm widget.

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.

See also:
Example:
var featureForm = new FeatureForm({
  viewModel: { // Autocasts as new FeatureFormViewModel()
    layer: featureLayer   // Associates the FeatureForm to the layer
  },
  container: "formDiv"
});

Constructors

new FeatureFormViewModel(properties)
Parameter:
properties Object
optional

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

Property Overview

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

The name of the class.

more details
more detailsAccessor
Graphic

The associated feature containing the editable attributes.

more details
more detailsFeatureFormViewModel
FieldConfig[]|FieldGroupConfig[]

Array of individual or grouped field configuration objects.

more details
more detailsFeatureFormViewModel
InputField[]|InputFieldGroup[]

The input fields and/or grouped field rendered by the FeatureForm widget.

more details
more detailsFeatureFormViewModel
FeatureLayer

Layer containing the editable feature attributes.

more details
more detailsFeatureFormViewModel
String

The widget's state.

more details
more detailsFeatureFormViewModel
Boolean

Indicates whether all input fields are valid.

more details
more detailsFeatureFormViewModel

Property Details

declaredClass Stringreadonly inherited

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

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

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. For an example of grouped field configurations, please refer to the Update Feature Attributes sample.

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"
    }]
  }]
});
inputField InputField[]|InputFieldGroup[]readonly

The input fields and/or grouped field rendered by the FeatureForm widget.

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

state Stringreadonly

The widget's state. Possible values are in the table below.

ValueDescription
readyDependencies are met and has valid property values.
disabledDependencies are missing and cannot provide valid inputs.
Default Value:disabled
valid Boolean

Indicates whether all input fields are valid.

Method Overview

NameReturn TypeSummaryClass
Boolean

Emits an event on the instance.

more details
more detailsFeatureFormViewModel
InputField

Convenience method to find input fields.

more details
more detailsFeatureFormViewModel
Object

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

more details
more detailsFeatureFormViewModel
Boolean

Indicates whether there is an event listener on the instance that matches the provided event name.

more details
more detailsFeatureFormViewModel
Object

Registers an event handler on the instance.

more details
more detailsFeatureFormViewModel

Fires the submit event.

more details
more detailsFeatureFormViewModel

Method Details

emit(type, event){Boolean}

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters:
type String

The name of the event.

event Object
optional

The event payload.

Returns:
TypeDescription
Booleantrue if a listener was notified
findField(fieldName){InputField}

Convenience method to find input fields.

Parameter:
fieldName String

The input field to find.

Returns:
TypeDescription
InputFieldReturns an instance of the InputField.
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 = formVM.getValues();
  // Call applyEdits on the featurelayer
  layer.applyEdits({
    // Pass in the updated field values
    updateFeatures: [{ attributes }]
  });
}
hasEventListener(type){Boolean}

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameter:
type String

The name of the event.

Returns:
TypeDescription
BooleanReturns true if the class supports the input event.
on(type, listener){Object}

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

Fires the submit event.

Example:
// Listen for when 'submit' is called.
// Once it is fired, update the feature.
formVM.on("submit", updateFeature);

// When the DOM's button (btnUpdate) is clicked,
// Update attributes of the selected feature.
document.getElementById("btnUpdate").onclick = function() {
  // Fires feature form's submit event.
  formVM.submit();
}

Event Overview

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

Fires when the submit() method is called.

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

Fires when a field value is updated.

more details
more detailsFeatureFormViewModel

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.

value Number|String|null

The updated field value.

valid Boolean

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

API Reference search results

NameTypeModule
Loading...