How to set a default value for edit widget field dynamically

1703
2
Jump to solution
05-28-2017 09:14 PM
AlistairFox
Occasional Contributor

I have a web app builder project that has an editable layer in it. The project ID is being based to the web app through the URL. I can grab this in javascript and use it. What I'd like to do is set the default value for the projectid field that is written by the edit widget when a new record is created. 

any pointers on where in the edit widget code I can intercept where the values are written and returned to the feature service?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Alistar,

  You can do that by modifying the edit widget _worksAfterCreate function:

     _worksAfterCreate: function(AddrPt2) { 
        // add close button to atiInspector
        this._addButtonToInspector();
        // resize editPopup
        this.editPopup.resize(500, 251);
        // update templatePicker for responsive.
        this.editor.templatePicker.update();       
//Add the autopopulate field value
        this.editor.templatePicker.on("selection-change", lang.hitch(this, function() {
          var selected = this.editor.templatePicker.getSelected(); 
          if (selected) { 
            var featureLayer = selected.featureLayer; 
            on.once(featureLayer, "before-apply-edits", lang.hitch(this, function(evt){
              if(evt.adds && evt.adds.length > 0){ 
                if(evt.adds[0].attributes.hasOwnProperty('ADDRESS')){ 
                evt.adds[0].attributes.ADDRESS = AddrPt2; 
                } 
                this.editor.attributeInspector.refresh();
              } 
            })); 
          }
        })); 
  //End add‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Alistar,

  You can do that by modifying the edit widget _worksAfterCreate function:

     _worksAfterCreate: function(AddrPt2) { 
        // add close button to atiInspector
        this._addButtonToInspector();
        // resize editPopup
        this.editPopup.resize(500, 251);
        // update templatePicker for responsive.
        this.editor.templatePicker.update();       
//Add the autopopulate field value
        this.editor.templatePicker.on("selection-change", lang.hitch(this, function() {
          var selected = this.editor.templatePicker.getSelected(); 
          if (selected) { 
            var featureLayer = selected.featureLayer; 
            on.once(featureLayer, "before-apply-edits", lang.hitch(this, function(evt){
              if(evt.adds && evt.adds.length > 0){ 
                if(evt.adds[0].attributes.hasOwnProperty('ADDRESS')){ 
                evt.adds[0].attributes.ADDRESS = AddrPt2; 
                } 
                this.editor.attributeInspector.refresh();
              } 
            })); 
          }
        })); 
  //End add‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
ArcGisServerPj
New Contributor

Hi. I have the same   issue. I don’t known where to put this function worksAfterCreate. I need your help.

0 Kudos