FeatureFormViewModel

AMD: require(["esri/widgets/FeatureForm/FeatureFormViewModel"], (FeatureFormVM) => { /* code goes here */ });
ESM: import FeatureFormVM from "@arcgis/core/widgets/FeatureForm/FeatureFormViewModel";
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. Although, editing attachments is possible using the Editor widget.

See also:
Example:
let 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.
Show inherited properties Hide inherited properties
Name Type Summary Class
Stringmore details

The name of the class.

more detailsAccessor
Graphicmore details

The associated feature containing the editable attributes.

more detailsFeatureFormViewModel
FormTemplatemore details

The associated template used for the form.

more detailsFeatureFormViewModel
InputField[]|InputFieldGroup[]more details

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

more detailsFeatureFormViewModel
FeatureLayer|SceneLayermore details

Layer containing the editable feature attributes.

more detailsFeatureFormViewModel
Stringmore details

The widget's state.

more detailsFeatureFormViewModel
Booleanmore details

When true, this form can be submitted without introducing data validation issues.

more detailsFeatureFormViewModel
Booleanmore details

Indicates whether all input fields are valid.

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
    }
  });
});
formTemplate FormTemplateautocast
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 and set any associated properties for the form, e.g. title, description, field elements, etc.

See also:
inputFields 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.

Value Description
ready Dependencies are met and has valid property values.
disabled Dependencies are missing and cannot provide valid inputs.

Possible Values:"ready"|"disabled"

Default Value:disabled
submittable Boolean

When true, this form can be submitted without introducing data validation issues.

valid Boolean

Indicates whether all input fields are valid.

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class
Booleanmore details

Emits an event on the instance.

more detailsFeatureFormViewModel
InputFieldmore details

Convenience method to find input fields.

more detailsFeatureFormViewModel
FeatureFormViewModel
Objectmore details

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

more detailsFeatureFormViewModel
Booleanmore details

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

more detailsFeatureFormViewModel
Objectmore details

Registers an event handler on the instance.

more detailsFeatureFormViewModel
more details

Adds one or more handles which are to be tied to the lifecycle of the object.

more detailsAccessor
more details

Used to set the updated field value.

more detailsFeatureFormViewModel
more details

Fires the submit event.

more detailsFeatureFormViewModel
Object[]FeatureFormViewModel

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:
Type Description
Boolean true if a listener was notified
findField(fieldName){InputField}

Convenience method to find input fields.

Parameter:
fieldName String

The input field to find.

Returns:
Type Description
InputField Returns an instance of the InputField.
get()inner
getValues(){Object}

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

Returns:
Type Description
Object An 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 feature layer
  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:
Type Description
Boolean Returns 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:

An event or an array of events to listen for.

listener Function

The function to call when the event fires.

Returns:
Type Description
Object Returns an event handler with a remove() method that should be called to stop listening for the event(s).
Property Type Description
remove Function When 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(handleOrHandles)inherited
Since: ArcGIS API for JavaScript 4.24

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.whenOnce(() => !view.updating)
  .then(() => {
    wkidSelect.disabled = false;
});

handle.remove();

// Assign a handle using own()
this.own(reactiveUtils.whenOnce(() => !view.updating)
  .then(() => {
    wkidSelect.disabled = false;
  }));
Parameter:
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

setValue(fieldName, value)
Since: ArcGIS API for JavaScript 4.21

Used to set the updated field value.

This renders the new value within the form but does not update the underlying input feature's attributes.

Parameters:
fieldName String

The target field to update.

The value to set on the target field.

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();
}
validateContingencyConstraints(values, options){Object[]}
Since: ArcGIS API for JavaScript 4.23
Parameters:
values String

A hash map of the form fields and their values.

options Object
optional

An object specifying additional options on what should be considered an error.

Specification:
includeIncompleteViolations Boolean
optional

If true, return contingency violations for field groups that are invalid because values have not yet been specified for all their fields. If false, any of these violations are ignored.

Returns:
Type Description
Object[] An array of objects, each representing a violation of a field group's contingent value rules.

Event Overview

Name Type Summary Class
{valid: String[],invalid: String[],values: Object}
more details

Fires when the submit() method is called.

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

Fires when a field value is updated.

more details FeatureFormViewModel

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:
layer FeatureLayer

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.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.