Custom editor field dijit, cascading pulldowns, and hooking onto the onchange event?

3044
5
Jump to solution
07-03-2015 09:17 AM
TimDine
Occasional Contributor II

This is a followup to https://community.esri.com/message/532305#532305

I have two fields using custom Dijits that are pulldowns populated from a store object.  The behavior I'd like to see is that when I change one of the pulldowns I hook onto that event and change the contents of the store for the other pulldown.  It is the same behavior you would see in ArcGIS desktop with changing a subtype and getting a new domain assigned to a field (except subtypes / domains are bugged in feature services and I want to chain together five of these fields in sequential pulldowns).

I've been fiddling with the onchange event of the dijit.  I can set it to be a function of my choosing.  The problem is that the viewer wants to replace the function I've assigned with the function it wants to assign as part of the out of the api.

function(){var h=g._toArray(arguments),e=c?(a||b.global):f;return e&&e.apply(a||this,d.concat(h))}

When I watch the requests being sent to the server this function is related to the applyedits method being called to write the new value to the server.

If I'm unable to override the onchange event of the dijit, is it going to be possible to have dijits that influence each other?  Is there another potential direction I could take to achieve this behavior?

0 Kudos
1 Solution

Accepted Solutions
TimDine
Occasional Contributor II

With some clearer thinking my issues with aspect seem to be that it isn't in Dojo 1.6 and therefore the ArcGIS javascript api.  http://dojotoolkit.org/reference-guide/1.6/dojo/aspect.html goes to nothing.  Without replacing anything and using a local api it looks like I can't use that.  The suggestion did lead me to the watch method which has let me build a series of five cascading Comboboxes which get their values from a rest service providing the valid values for the previously selected Combobox!

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Tim,

   If you want to capture an event before, durring, or after then you need to look into using dojo/aspect.

0 Kudos
TimDine
Occasional Contributor II

That looks exactly like what I'm looking for.  I haven't gotten it to work.

Looking at this sample Avoiding onChange on ComboBox when chaning selection dynamically - JSFiddle I've blended that into my code.  The ON seems to get overwritten just like the regular onChange which I'd expect, the WATCH looks great and I may be able to get the behavior I need from it, the AFTER bombs with a "TypeError: Unable to get property 'after' of undefined or null reference".

I've placed the dojo/aspect in my define block at the top of the widget, and included aspect in the function declaration of the widget.  It seems that it 'should' be fine...  Have I missed a concept somewhere?

The code below is in my onOpen function of the Edit widget.  I've tried a variation of it in the getLayers sections of the code as well.

 this.assetCodeComboBoxDijit = new dijit.form.ComboBox({
  store:this.assetStores.codeStore
  });
 console.log(this.assetCodeComboBoxDijit);
 //this.assetCodeComboBoxDijit.on("change", function(value) { console.log("on:", value); });
 //this.assetCodeComboBoxDijit.watch("value", function(name, oldValue, newValue) {console.log("watch:", name, oldValue,newValue);});
 aspect.after(this.assetCodeComboBoxDijit, "onChange", function(duno, value) {
            console.log("onChange:", value);
        });
0 Kudos
TimDine
Occasional Contributor II

With some clearer thinking my issues with aspect seem to be that it isn't in Dojo 1.6 and therefore the ArcGIS javascript api.  http://dojotoolkit.org/reference-guide/1.6/dojo/aspect.html goes to nothing.  Without replacing anything and using a local api it looks like I can't use that.  The suggestion did lead me to the watch method which has let me build a series of five cascading Comboboxes which get their values from a rest service providing the valid values for the previously selected Combobox!

RobertScheitlin__GISP
MVP Esteemed Contributor

Tim,

   I use aspect often in my code and so does esri WAB widgets.

0 Kudos
TimDine
Occasional Contributor II

Hmm, somewhere I've got a keyboard operator error then.  I'll give it another shot and see what I can make happen.

0 Kudos