Curious if anyone's had any success with this. Here's the scenario:
I have an app built with edit abilities. The user is placing points within parcels and one of the editable fields in the points feature is the Parcel PIN number. Currently they're clicking the parcel, copying the PIN, opening the Edit widget, placing a dot within the parcel, then pasting the PIN number into the field. I'm sure there's a way to run a Query in the background that fires on the click that creates the point and can autopopulate the PIN field, but it's beyond me.
Anyone have any suggestions?
This is as far as I've gotten in terms of trying to get the Query into the Edit widget. I'm not sure whether I need to include a QueryTask, a FeatureSet, an AttributeInspector or a RelationshipQuery as well.
_worksAfterCreate: function(settings) {
// add close button to atiInspector
this._addButtonToInspector();
// resize editPopup
this.editPopup.resize(500, 251);
// update templatePicker for responsive.
this.editor.templatePicker.update();
//Add the layer for the query to run against
//Add the query. Might not need
// this.pinQuery = new Query ({
// spatialRelationship: Query.SPATIAL_REL_WITHIN,
// outFields: ["PIN"]
// });
//Execute the query. Used this.map.on to symbolize it's when the map is clicked
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){
var pinLayer = new FeatureLayer ("REST URL FOR PARCELS", {
id: "pinLayer",
mode: FeatureLayer.MODE_SELECTION,
outFields: ["*"]
});
this.map.addLayer(pinLayer);
var pinQuery = new Query();
//var pinQueryTask = new QueryTask("REST URL FOR PARCELS");
pinQuery.geometry = evt.mapPoint;
pinQuery.outFields = ["PIN"];
pinQuery.spatialRelationship = Query.SPATIAL_REL_WITHIN;
pinLayer.selectFeatures(pinQuery, FeatureLayer.SELECTION_NEW, function(features){
if(evt.adds && evt.adds.length > 0){
if(evt.adds[0].attributes.hasOwnProperty('PIN')){
evt.adds[0].attributes.PIN = ["PIN"]; //PIN = 'PIN'; returns PIN in field
}
this.editor.attributeInspector.refresh();
}})
}));
}
}));
//just for BoxTheme
setTimeout(lang.hitch(this, this._update), 900);
this._addFilterEditor(settings);
this._createOverDef.resolve();
},