how to set default values for editor widget esri 4 programmatically
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") } });
Default values can only be set when publishing the services. Adding default values via the Editor widget is not supported.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.