Select to view content in your preferred language

how to set default values for editor widget esri 4 programmatically

679
2
09-09-2022 07:02 AM
karimkimo
New Contributor

how to set default values for editor widget esri 4 programmatically  

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor II

Default values can only be set when publishing the services. Adding default values via the Editor widget is not supported.

0 Kudos
MatthiasKl
New Contributor III

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")
  }
});