1

In previous iterations of the ArcGIS Javascript API (3.X), you were able to listen for the "before-apply-edits" event when hooked to your feature layer . I can't seem to find this same event when looking at the 4.29 API reference. I can only find the event "edits", which only fires AFTER the applyEdits function completes.

Question: How can I listen for and access the edited features attributes before the edits are applied in the ArcGIS Javascript API 4.29. I would like to compare the feature's original attribute values to the feature's new attribute values after applyEdits finishes.

Or maybe there are some events related to the Editor widget that I'm missing that could help me out. I'd rather not resort storing the state of attributes every time the user changes their selection, rather, be able to access them in real time during the applyEdits event loop.

5
  • It looks like the only way is to watch editor widget sketch-update event, which is fired at the start of the edit and at the end of the edit.
    – TomazicM
    Commented May 7 at 6:55
  • I saw that, but unfortunately it seems that it fires for graphic/geometry updates only, unless I'm mistaken Commented May 7 at 7:09
  • Unfortunately you are not mistaken.
    – TomazicM
    Commented May 7 at 19:01
  • There is an "apply-edits" event in the layer passing two arguments. One of the argument is a promise of a result property. If you await for that promise the modifications are already applied. If you do not wait it is supposed to be "before" edits. But unfortunately I could not figure out how to modify e.g. the feature attributes during this
    – Ole K
    Commented May 8 at 5:53
  • 1
    @OleK Where did you find this event?
    – TomazicM
    Commented May 8 at 7:53

2 Answers 2

1

Previously I have given the hint using the layer event apply-edits which I have reverse engineered. It's suitable, but difficult to manage features attribute changes for instance.

Best approach I guess is to use the submit event from FeatureFormViewModel (https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureForm-FeatureFormViewModel.html#event-submit) hidden in the EditorViewModel

1

Update:

Thanks to @Ole K, I was able to get this working. Here is how I did it if anyone else runs into this issue as accessing the FeatureFormViewModel for the Editor widget is not straight-forward.

To access the Editor Widget's encapsulated FeatureFormViewModel, you access it through it's viewModel property:

editor.viewModel.featureFormViewModel

This will return null, however, if it has not been opened by starting an edit session on a feature, and thus cannot attach an event handler to the submit event. So, using reactiveUtils, I wrote a listener that will attach a submit event handler once the featureFormViewModel has been instantiated and the view model's state has switched from ready to editing-attributes.

reactiveUtils.when(() => editor.viewModel.state == "editing-attributes", () => editor.viewModel.featureFormViewModel.on("submit", (e)=><do stuff...>);

I suppose one could also listen for editor.viewModel.featureFormViewModel != null to access apply the event handler to the submit event if you didn't want to wait for a specific state change

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.