Edit widget - start editing without template picker

1171
5
Jump to solution
08-15-2018 10:22 AM
ZorbaConlen1
Occasional Contributor III

Hi,

I'm developing an editing app and extending the WAB Edit widget for some custom behavior. I'm programmatically launching the edit widget, but I don't want to make users pick the edit type from the template picker. Rather, I'd like to just allow them to start editing a hard coded feature layer. And I would hide the template picker as well.

Struggling so far to figure out how to go about this. I know the edit widget uses the esri editor digit. I'm assuming there is a method that starts editing for that digit, but not finding it, so far... 

Thanks

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Zorba,

   I have some code that will automatically choose a template to start the editing but hiding the template picker can be problematic as once a new feature is added you need to re-select another template to continue editing.

In the Edit Widgets Widget.js find the _createEditor function and add lines 11-18 (changing the name of your desired template of course).

      _createEditor: function() {
        var params = {
          settings: this._getSettingsParam()
        };
        this._settingsParam = params.settings;
        this._worksBeforeCreate(params.settings);
        this.editor = new Editor(params, html.create("div", {}, this.domNode));
        this.editor.startup();
        this._worksAfterCreate(params.settings);

        query("[id*='tpick-surface-']", this.editor.templatePicker.domNode).forEach(function(template){
          if(template.innerText && template.innerText.trim() === 'Robbery'){
            on.emit(template, "click", {
              bubbles: true,
              cancelable: true
            });
          }
        });
      },

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Zorba,

   I have some code that will automatically choose a template to start the editing but hiding the template picker can be problematic as once a new feature is added you need to re-select another template to continue editing.

In the Edit Widgets Widget.js find the _createEditor function and add lines 11-18 (changing the name of your desired template of course).

      _createEditor: function() {
        var params = {
          settings: this._getSettingsParam()
        };
        this._settingsParam = params.settings;
        this._worksBeforeCreate(params.settings);
        this.editor = new Editor(params, html.create("div", {}, this.domNode));
        this.editor.startup();
        this._worksAfterCreate(params.settings);

        query("[id*='tpick-surface-']", this.editor.templatePicker.domNode).forEach(function(template){
          if(template.innerText && template.innerText.trim() === 'Robbery'){
            on.emit(template, "click", {
              bubbles: true,
              cancelable: true
            });
          }
        });
      },
LauraGiboo
New Contributor III

What if I don't have a template to select?  In this case, I have a feature service where users can update information on existing features so there is no new point to create, thus no template.  How would I make that work in your sample code above?

 

LauraGiboo1_0-1616173507089.png

 

0 Kudos
ZorbaConlen1
Occasional Contributor III

Thanks for the snippet Robert. Just gave it a try and it works as expected.

I'm marking this as the answer, but that said, still interested in entirely decoupling editing from the templatepicker module, if possible. For example, I only want the layer in question edited via a feature action, so, I don't even want to show that symbol in the template picker. This approach is great, but I'll need to do some extra customization to ensure that only the desired layers are shown in the picker, when the edit widget is activated.

I had anticipated that the templatepicker or editor classes would have a method that accepts a parameter indicating which template to activate editing for. Perhaps a good enhancement for ESRI to consider, as there are cases where the templatepicker interface is problematic or unnecessary.

Thanks again

Zorba

AndresCastillo
MVP Regular Contributor

Also, maybe try this workflow:

Make a relationship between a FC and table.

At least for the smart editor widget, you can disable editing on the FC, but not the table.

Doing this will bypass the template picker, and the user can go straight into editing related table records for the parent FC.

0 Kudos
ZorbaConlen1
Occasional Contributor III

Good thought. Thanks Andres.