Is it possible to set default values for fields with the Editor widget?

4898
13
12-02-2019 03:47 PM
ZoeZaloudek
Occasional Contributor

I'm exploring using the Editor widget (with version 4.12) in a web map.  This web map asks users to draw a polygon, then attribute the polygon with comment text and contact info.  There are 6 fields for the user to fill out. 

Since I'm asking folks to add multiple polygons, I'd like to cut down on the amount of typing they have to do by pre-populating the contact info fields.  I have a splash screen that asks for this info when they first get to the web map, so it's already saved to string variables in my JS code.  Can I assign these values to the text boxes in the Editor widget right after a user completes a new polygon, so they don't have to repeatedly type in these values every time they add a new feature?  This seems like something that could be in the layerInfos > fieldConfig property.

0 Kudos
13 Replies
EthanVodra
New Contributor II

Thanks that helps alot I'm only dealing with a single type of polygon so don't have any domains/subtypes (and therefore tempates) defined for my layer. Would you happen to know how to get the editor widget to fire an event when the "Add Feature" is clicked?

EthanVodra
New Contributor II

Never mind. Realized I can use the "activeWorkflow" property to achieve the same end.

As below, I can use a double-click listener event on the map view (similar to what you have done above) to listen for a double-click event that happens when a user finishes creating a feature. Then I can check the activeWorkflow.started property to determine that my double click is actually from finishing creating a feature (rather than the user just randomly double clicking on the map). I should be able to jump in here and assign my attributes here hopefully.

view.on("double-click", function(event){
   
   console.log("double-click detected");
            
   if(editor.activeWorkflow != null && editor.activeWorkflow.started == true) {
      console.log(editor.activeWorkflow.started);
   };‍‍‍‍‍‍‍
0 Kudos
EthanVodra
New Contributor II

Stuck again! I'm really struggling to see how you are able to populate the FeatureForm associated with the Editor widget!?

If I understand the example you linked correctly, it essentially creates the feature immediately and applies the attributes to "in the background". It then immediate loads the FeatureForm for the newly created feature, giving the user the opportunity to edit the default attributes. It is not really "pre-populating" fields before the feature is created but rather assigning values to the fields straightaway.

I don't see how this can be achieved with the Editor Widget. When adding a feature using the editor widget the user must fill out the fields and press the "Apply" button before the feature is created. Therefore we can't assign attributes to a feature before it is created so I don't see how the fields can be "pre-populated" in this case.

ZA1
by
New Contributor III

Hi EdDempsey

Could you please explain through code how you were able to automatically populate the field. 

Thank you

0 Kudos