require(["esri/widgets/FeatureForm/FeatureFormViewModel"], (FeatureFormVM) => { /* code goes here */ });
import FeatureFormVM from "@arcgis/core/widgets/FeatureForm/FeatureFormViewModel.js";
esri/widgets/FeatureForm/FeatureFormViewModel
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.
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
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
The name of the class. | Accessor | ||
The associated feature containing the editable attributes. | FeatureFormViewModel | ||
The associated template used for the form. | FeatureFormViewModel | ||
The field, group, or relationship inputs that make up the form FeatureForm widget. | FeatureFormViewModel | ||
Layer containing the editable feature attributes. | FeatureFormViewModel | ||
A reference to the associated Map. | FeatureFormViewModel | ||
The widget's state. | FeatureFormViewModel | ||
Indicates if the field's value can be submitted without introducing data validation issues. | FeatureFormViewModel | ||
The timezone displayed within the form. | FeatureFormViewModel | ||
Indicates whether the form is currently updating. | FeatureFormViewModel | ||
Indicates whether all of the input fields are valid. | FeatureFormViewModel |
Property Details
-
feature
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
formTemplate FormTemplateautocast
Since: ArcGIS Maps SDK for JavaScript 4.16FeatureFormViewModel since 4.9, formTemplate added at 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.
-
inputs
inputs Array<(FieldInput|GroupInput|RelationshipInput)>readonly
Since: ArcGIS Maps SDK for JavaScript 4.27FeatureFormViewModel since 4.9, inputs added at 4.27. -
The field, group, or relationship inputs that make up the form FeatureForm widget.
-
layer
layer FeatureLayer |SceneLayer |SubtypeSublayer
-
Layer containing the editable feature attributes. If this layer is not specified, it is the same as the graphic's layer.
-
map
map Map
Since: ArcGIS Maps SDK for JavaScript 4.27FeatureFormViewModel since 4.9, map added at 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
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
submittable Boolean
-
Indicates if the field's value can be submitted without introducing data validation issues.
-
timeZone
timeZone String
Since: ArcGIS Maps SDK for JavaScript 4.28FeatureFormViewModel since 4.9, timeZone added at 4.28. -
The timezone displayed within the form. If
unknown
, it will display the preferredTimeZone of the layer. If this layer property is not set, it will default to UTC.
-
updating
updating Booleanreadonly
Since: ArcGIS Maps SDK for JavaScript 4.27FeatureFormViewModel since 4.9, updating added at 4.27. -
Indicates whether the form is currently updating.
-
valid
valid Booleanreadonly
-
Indicates whether all of the input fields are valid.
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. | Accessor | ||
Convenience method to find field inputs. | FeatureFormViewModel | ||
Returns all of the field values, regardless of whether or not they were updated. | FeatureFormViewModel | ||
Returns true if a named group of handles exist. | Accessor | ||
Registers an event handler on the instance. | FeatureFormViewModel | ||
Removes a group of handles owned by the object. | Accessor | ||
The method used to set the updated field value. | FeatureFormViewModel | ||
Fires the submit event. | FeatureFormViewModel | ||
Validates whether a feature's attribute values conform to the defined contingent values. | FeatureFormViewModel |
Method Details
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, addHandles added at 4.25. -
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.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
findField
findField(fieldName){FieldInput}
-
Convenience method to find field inputs.
ParameterfieldName StringThe input field to find.
ReturnsType Description FieldInput Returns an instance of the FieldInput.
-
getValues
getValues(){Object}
-
Returns all of the field values, regardless of whether or not they were updated.
ReturnsType Description Object An object of key-value pairs of field names with their values. Examplefunction 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 }] }); }
-
hasHandles
InheritedMethodhasHandles(groupKey){Boolean}
Inherited from AccessorSince: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, hasHandles added at 4.25. -
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
on
on(type, listener){Object}
-
Registers an event handler on the instance. Call this method to hook an event with a listener.
ParametersReturnsType 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. Exampleview.on("click", function(event){ // event is the event handle returned after the event fires. console.log(event.mapPoint); });
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, removeHandles added at 4.25. -
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
-
Since: ArcGIS Maps SDK for JavaScript 4.21FeatureFormViewModel since 4.9, setValue added at 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
-
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(); }
-
Since: ArcGIS Maps SDK for JavaScript 4.23FeatureFormViewModel since 4.9, validateContingencyConstraints added at 4.23. -
Validates whether a feature's attribute values conform to the defined contingent values.
Parametersvalues StringA hash map of the form fields and their values.
options ObjectoptionalAn object specifying additional options on what should be considered an error.
SpecificationincludeIncompleteViolations BooleanoptionalIf
true
, return contingency violations for field groups that are invalid because values have not yet been specified for all their fields. Iffalse
, any of these violations are ignored.ReturnsExample// 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!"); });
Event Overview
Name | Type | Summary | Class |
---|---|---|---|
|
{valid: String[],invalid: String[],values: Object} |
Fires when the submit() method is called. |
FeatureFormViewModel |
|
{layer: FeatureLayer,feature: Graphic,fieldName: String,value: Number|String|null,valid: Boolean} |
Fires when a field value is updated. |
FeatureFormViewModel |
Event Details
-
Fires when the submit() method is called. Call FeatureLayer.applyEdits() method to update a feature's attributes.
- Properties
- See also
Example// Listen for the submit event. featureFormVM.on("submit", function(){ if (editFeature) { // Grab updated attributes from the form. const updated = featureFormVM.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); } });
-
Fires when a field value is updated.