Skip to content
import FeatureFormViewModel from "@arcgis/core/widgets/FeatureForm/FeatureFormViewModel.js";
Inheritance:
FeatureFormViewModelAccessor
Since
ArcGIS Maps SDK for JavaScript 4.9

Provides the logic for the FeatureForm widget.

Known Limitations

This widget is not yet at full parity with the functionality provided in the 3.x AttributeInspector widget. There is currently no support for editing attachments or related records solely within this widget, although it is possible to edit attachments and relationship data via the Editor widget. Please refer to the Editor documentation for any known limitations regarding this.

See also
Example
let featureForm = new FeatureForm({
viewModel: { // Autocasts as new FeatureFormViewModel()
map: map, // Required if using Arcade expressions that use the global $map variable
layer: featureLayer // Associates the FeatureForm to the layer
},
container: "formDiv"
});

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

activeAssociation

autocast Property
Type
Association | null | undefined

The [Association]Association that the selected feature is involved in. The association is provided by the activeAssociationInput of the previous Editor workflow.

This property is null until the user has drilled into an associated feature in the Editor widget.

activeAssociationInput

readonly Property
Type
UtilityNetworkAssociationInput | null | undefined

The [UtilityNetworkAssociationInput]UtilityNetworkAssociationInput providing association data for the active workflow and selected association type in the Editor widget.

This property is null until an association type is selected in the Editor widget.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

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

editType

Property
Type
EditType
Since
ArcGIS Maps SDK for JavaScript 4.33

The edit type for the form, which determines the editing context and behavior.

This property is used in two primary ways:

  1. Arcade Expressions Context: When evaluating Arcade expressions, the value of this property is assigned to the $editContext.editType variable. This allows Arcade expressions to adapt their behavior based on the type of edit being performed (e.g., "INSERT", "UPDATE", "DELETE", or "NA").

  2. Layer Editing Capabilities: This property is also used to determine whether the layer allows the specified type of edit. For example:

    • If editType is set to "INSERT" but the layer has supportsAdd: false, all inputs in the form will be read-only.
    • If editType is set to "UPDATE" but the layer has supportsUpdate: false, all inputs will also be read-only.

This behavior applies regardless of whether a form template or Arcade expressions are present. For instance:

  • If a layer has { supportsAdd: true, supportsUpdate: false } and no form template, setting editType to "INSERT" will allow the user to modify all fields, while setting it to "UPDATE" will make all fields read-only.
  • If a form template is present with field elements that include editableExpression or valueExpression, the editType still determines whether the layer permits editing in the given context.
See also
Default value
"NA"

feature

Property
Type
Graphic | null | undefined

The associated feature containing the editable attributes. A common way to access this is via the MapView.hitTest() 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

autocast Property
Type
FormTemplate | null | undefined
Since
ArcGIS Maps SDK 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

inputs

readonly Property
Type
Array<FeatureFormSupportedInput>
Since
ArcGIS Maps SDK for JavaScript 4.27

The field, group, or relationship inputs that make up the form FeatureForm widget.

layer

Property
Type
FeatureFormLayerUnion | null | undefined

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

map

Property
Type
EsriMap | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.27

A reference to the associated Map.

This property is required if working with Arcade expressions in the FeatureForm that make use of the $map global variable.

state

readonly Property
Type
FeatureFormViewModelState

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"

submittable

readonly Property
Type
boolean

Indicates if the field's value can be submitted without introducing data validation issues.

timeZone

autocast Property
Type
TimeZone
Since
ArcGIS Maps SDK for JavaScript 4.28

The timezone displayed within the form. If unknown, it will display the FeatureLayer.preferredTimeZone of the layer. If this layer property is not set, it will default to UTC.

updating

readonly Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.27

Indicates whether the form is currently updating.

valid

readonly Property
Type
boolean

Indicates whether all of the input fields are valid.

Methods

MethodSignatureClass
emit
inherited
emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
findField(fieldName: string | null | undefined): FieldInput | null | undefined
getValues(): Attributes
hasEventListener
inherited
hasEventListener<Type extends EventNames<this>>(type: Type): boolean
isFulfilled
inherited
isFulfilled(): boolean
isRejected
inherited
isRejected(): boolean
isResolved
inherited
isResolved(): boolean
on
inherited
on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
setValue(fieldName: string, value: FieldValue): void
submit(): void
validateContingencyConstraints(values: Attributes, options?: FeatureFormViewModelValidateContingencyConstraintsOptions): object[]
when
inherited
when<TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>

emit

inherited Method
Signature
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

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

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

event
this["@eventTypes"][Type]

The event payload.

Returns
boolean

true if a listener was notified

findField

Method
Signature
findField (fieldName: string | null | undefined): FieldInput | null | undefined

Convenience method to find field inputs.

Parameters
ParameterTypeDescriptionRequired
fieldName

The input field to find.

Returns
FieldInput | null | undefined

Returns an instance of the FieldInput.

getValues

Method
Signature
getValues (): Attributes

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

See also
Returns
Attributes

An object of key-value pairs of field names with their values.

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

inherited Method
Signature
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

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

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

Returns
boolean

Returns true if the class supports the input event.

isFulfilled

inherited Method
Signature
isFulfilled (): boolean
Inherited from: EsriPromiseMixin

isFulfilled() may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected). If it is fulfilled, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been fulfilled (either resolved or rejected).

isRejected

inherited Method
Signature
isRejected (): boolean
Inherited from: EsriPromiseMixin

isRejected() may be used to verify if creating an instance of the class is rejected. If it is rejected, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been rejected.

isResolved

inherited Method
Signature
isResolved (): boolean
Inherited from: EsriPromiseMixin

isResolved() may be used to verify if creating an instance of the class is resolved. If it is resolved, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been resolved.

on

inherited Method
Signature
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

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

Parameters
ParameterTypeDescriptionRequired
type
Type

An event or an array of events to listen for.

listener
EventedCallback<this["@eventTypes"][Type]>

The function to call when the event fires.

Returns
ResourceHandle

Returns an event handler with a remove() method that should 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);
});

setValue

Method
Signature
setValue (fieldName: string, value: FieldValue): void
Since
ArcGIS Maps SDK for JavaScript 4.21

The method 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
ParameterTypeDescriptionRequired
fieldName

The target field to update.

value

The value to set on the target field.

Returns
void

submit

Method
Signature
submit (): void

Fires the @submit event.

Returns
void
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

Method
Signature
validateContingencyConstraints (values: Attributes, options?: FeatureFormViewModelValidateContingencyConstraintsOptions): object[]
Since
ArcGIS Maps SDK for JavaScript 4.23

Validates whether a feature's attribute values conform to the defined contingent values.

Parameters
ParameterTypeDescriptionRequired
values

A hash map of the form fields and their values.

options

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

Returns
object[]

An array of objects, each representing a violation of a field group's contingent value rules.

Example
// Validate a features attribute values against the layer's contingent values
featureForm.on("value-change", () => {
const validations = featureForm.viewModel.validateContingencyConstraints(featureForm.getValues());
!!validations.length ? console.log("found some validation errors: ", validations) : console.log("no errors found!");
});

when

inherited Method
Signature
when <TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>
Type parameters
<TResult1 = this, TResult2 = never>
Inherited from: EsriPromiseMixin

when() may be leveraged once an instance of the class is created. This method takes two input parameters: an onFulfilled function and an onRejected function. The onFulfilled executes when the instance of the class loads. The onRejected executes if the instance of the class fails to load.

Parameters
ParameterTypeDescriptionRequired
onFulfilled

The function to call when the promise resolves.

onRejected

The function to execute when the promise fails.

Returns
Promise<TResult1 | TResult2>

Returns a new promise for the result of onFulfilled that may be used to chain additional functions.

Example
// Although this example uses MapView, any class instance that is a promise may use when() in the same way
let view = new MapView();
view.when(function(){
// This function will execute once the promise is resolved
}, function(error){
// This function will execute if the promise is rejected due to an error
});

Events

submit

Event

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

See also
bubbles composed cancelable
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

Event
value-change: CustomEvent<ValueChangeEvent>

Fires when a field value is updated.

bubbles composed cancelable

Type definitions

SubmitEvent

Type definition

invalid

Property
Type
string[]

The invalid field names.

valid

Property
Type
string[]

The valid field names.

values

Property
Type
Attributes

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

ValueChangeEvent

Type definition

layer

Property
Type
FeatureLayer | null | undefined

The associated feature layer.

feature

Property
Type
Graphic | null | undefined

The associated feature.

fieldName

Property
Type
string

The updated field.

value

Property
Type
FieldValue

The updated field value.

valid

Property
Type
boolean

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

FeatureFormViewModelState

Type definition
Type
"disabled" | "ready"

FeatureFormViewModelValidateContingencyConstraintsOptions

Type definition

includeIncompleteViolations

Property
Type
boolean

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.