javascript - Modify Search Widget Value Before Searching for Results -
i've search widget on map. i'm trying when user types, let's say, 1215 bourboun st
, want append sacramento, us
value very precised results returned back.
i've looked @ documentation , found search-results
event, lets me play around returned results. there event can subscribe takes place before search done? enable me modify search value before initiating search.
my code follows:
map = new map("mapdiv", { center: [xyz, abc], zoom: 10, basemap: "streets" }); var search = new search({ map: map }, dom.byid("search")); search.startup(); search.on("search-results", populatehiddenfield); . . . // irrelevant code
update
using gary's suggestion, created fiddle let experts me out on one.
case scenario:: if start typing 1215
, you'll notice returns result on world , not sacramento though i've extended search
class per gary's suggestion. there way can restrict autosuggestions sacramento alone?
update: question edited enable suggestions instead of disabling them, , have updated answer accordingly. handling suggestions simple overriding suggest
method in same way search
method.
create new class extends search
, override search
function.
map = new map("mapdiv", { center: [xyz, abc], zoom: 10, basemap: "streets" }); //define new class inherits search var mysearch = declare(search, { //override search method search: function () { var originalvalue = this.value; this.set("value", this.value + ", sacramento, ca"); var retval = this.inherited(arguments); this.set("value", originalvalue); return retval; } //override suggest method suggest: function () { var originalvalue = this.value; this.set("value", this.value + ", sacramento, ca"); var retval = this.inherited(arguments); this.set("value", originalvalue); return retval; } }); var search = new mysearch({ map: map, enablesuggestionsmenu:true, enablesuggestions:true, autoselect:true, autonavigate:true }, dom.byid("search")); search.startup(); search.on("search-results", populatehiddenfield);
you'll need include "dojo/_base/declare"
in require
list.
see http://dojotoolkit.org/documentation/tutorials/1.10/declare/ more details on extending dojo class.
Comments
Post a Comment