Select to view content in your preferred language

Preset value in Editor widget in a JS app using the setValue

404
1
Jump to solution
11-21-2023 12:16 PM
LefterisKoumis
Frequent Contributor

I have this simple JS app and trying to preset the value of a field. On this example is the Phone Number field but I want to know what am I doing wrong and I can't preset it using the setValue property.

This is the property:

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureForm-FeatureFormVi...

Here is the app. 

 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

I found adding a bit of asynchronous delay seems to do the trick:

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

 

You'll want to be careful this workflow doesn't inadvertently overwrite something the user manually enters; I didn't test for that kind of thing.

View solution in original post

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

I found adding a bit of asynchronous delay seems to do the trick:

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

 

You'll want to be careful this workflow doesn't inadvertently overwrite something the user manually enters; I didn't test for that kind of thing.

0 Kudos