From 4ae4e4ab32d0888ef1b9d59986c673fa3aea4504 Mon Sep 17 00:00:00 2001 From: Andy Mercer Date: Wed, 10 Aug 2016 12:34:44 -0400 Subject: [PATCH] Allow for Searchboxes to have default values --- mapstractor.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/mapstractor.js b/mapstractor.js index 0e4f98d..f5f502a 100644 --- a/mapstractor.js +++ b/mapstractor.js @@ -340,6 +340,15 @@ /* componentRestrictions:{country:'us'} */ var searchOptions = 'searchOptions' in params ? params.searchOptions : {}; + /* Variable: defaultValue */ + /* Type: String */ + /* Default: '' */ + /* Purpose: This string is the default address */ + /* of the searchbox. It is blank unless */ + /* specified. If it is specified, a */ + /* place_changed event is triggered. */ + var defaultValue = 'defaultValue' in params ? params.defaultValue : ''; + /* Variable: showSearchButton */ /* Type: Boolean */ /* Default: true */ @@ -365,7 +374,15 @@ /* typing in the search box. */ var showAutocompleteList = 'showAutocompleteList' in params ? params.showAutocompleteList : false; - /* Variable: placefoundCallback */ + /* Variable: runDefaultPlaceCallback */ + /* Type: Boolean */ + /* Default: true */ + /* Purpose: This boolean determines whether the */ + /* place found callback should be run */ + /* when the default place is found. */ + var runDefaultPlaceCallback = 'runDefaultPlaceCallback' in params ? params.runDefaultPlaceCallback : true; + + /* Variable: placefoundCallback */ /* Type: Function */ /* Default: function(){} */ /* Purpose: This function is the callback which */ @@ -476,6 +493,22 @@ } + // IF DEFAULT IS SPECIFIED, TRIGGER A place_changed EVENT ON THE SEARCHBOX + // THIS IS INSIDE OF THE TIMEOUT BECAUSE IT REQUIRES THAT THE self.autoCompletelist + // VARIABLE HAS BEEN CREATED. + + if ( defaultValue ) { + + searchInputElement.value = defaultValue; + + if (runDefaultPlaceCallback) { + + google.maps.event.trigger(gSearchBox, 'place_changed'); + + } + + } + }, 500); } @@ -765,6 +798,7 @@ if ( tagName == 'input' ) { element.type = type; } + } if ( tagName == 'button' ) { element.type = 'button';