how to set default values for editor widget esri 4 programmatically
Default values can only be set when publishing the services. Adding default values via the Editor widget is not supported.
Well, it is possible to prefill the FeatureForm by using the setValue method.
const editor = new Editor({
view: view,
});
editor.watch("viewModel.featureFormViewModel.feature", () => {
editor.viewModel.featureFormViewModel.setValue("Description", "Test")
});
(In my example, "Description" is the name of the Field, "Test" the value)
At least that's my current approach. But I'm still struggling to limit this so it only prefills the field of newly created features and not when editing already existing features. Does anyone know how this could be implemented?
---
Edit: Some spaghetti code which seems to work.
const editor = new Editor({
view: view,
});
editorVM = editor.viewModel;
editorVM.watch(['state', 'featureFormViewModel.feature'], () => {
if (editorVM.state == 'creating-features' && editorVM.featureFormViewModel.feature !== 'undefined') {
editorVM.featureFormViewModel.setValue("Description", "Test")
}
});