I am working on an application designed for users to make some simple feature layer edits. The users have full add/update/delete privileges. Another portion of the application generates a string value. I would like to have this value automatically included as the value of one of the fields whenever a user makes an edit. I don't care if the user sees this value or not, but the user should not be able to change it.
In a similar application, I was able to do this using @JoelBennett's solution from this post.
editorVM.watch(['state', 'featureFormViewModel.feature', 'featureFormViewModel.state'], () => {
if (editorVM.state == 'creating-features' && editorVM.featureFormViewModel.feature && editorVM.featureFormViewModel.state == 'ready') {
window.setTimeout(function() {
editorVM.featureFormViewModel.setValue('PhoneNumber', "999.999.999")
}, 200);
}
});But there are two complications for this application.
- This time I am using the Editor Component, not the Editor Widget, and the widget view model does not appear to be accessible through the Component.
- This application also has a FeatureTable Component that is editable and I also want the value injected when editing is done through the table.
Feature layers have the edits event that can be watched for, but it happens after the applyEdits() method completes. If I try to use applyEdits() inside this event, I will create an infinite loop. The code I want to write would intercept before the applyEdits() method is called, inject my value into the attributes and then proceed saving the edits.
Goal: Automatically add string variable to the attributes of a Feature Layer whenever it is edited in an application.
Restrictions:
- Users cannot alter this value.
- Must work with both Editor and FeatureTable Components.