bjorn2404 / jQuery-Store-Locator-Plugin

A store locator plugin using Google Maps API version 3
MIT License
495 stars 235 forks source link

Passing Form Data To The callbackSuccess #77

Closed frankthoeny closed 8 years ago

frankthoeny commented 9 years ago

I need some help understanding how the callbackSuccess method handles data. Data is undefined and the debug is on. I can see the following objects after entering my zipcode.

lat, lng, origin, name, distance

I have a couple of hidden fields in my form and I want to pass data to the callbackSuccess method.

Form

<form id="bh-sl-user-location" method="post" action="#">
<input type="hidden" id="maxdistance" name="maxdistance" value="100">
<input type="hidden" id="productID" name="productID" value="10">
 <input type="hidden" id="productSize" name="productSize" value="small">
 <div class="form-input">
 <label for="bh-sl-address">Enter Address or Zip Code:</label>
 <input type="text" id="bh-sl-address" name="bh-sl-address" />
 </div>
 <button id="bh-sl-submit" type="submit">Submit</button>
</form>

Store Locator

$('#map-container').storeLocator({
'debug': true,
'dataType': 'json',
'dataLocation': "json/locations.json",
'mapID': 'bh-sl-map',
'locationList': 'bh-sl-loc-list',
'formContainer': 'bh-sl-form-container',
'formID': 'bh-sl-user-location',
'addressID': 'bh-sl-address',
'slideMap': false,
'fullMapStart': true,
'storeLimit': 25,
'distanceAlert': 30,
'querystringParams' : true,
'maxDistance': true,  
'invertDistanceError': true, 
'infowindowTemplatePath' : 'assets/js/plugins/storeLocator/templates/infowindow-description.html',
'listTemplatePath': 'assets/js/plugins/storeLocator/templates/location-list-description.html',
'KMLinfowindowTemplatePath': 'assets/js/plugins/storeLocator/templates/kml-infowindow-description.html',
'KMLlistTemplatePath': 'assets/js/plugins/storeLocator/templates/kml-location-list-description.html',
'callbackSuccess': function(data) {      
        console.log(data);
}
bjorn2404 commented 9 years ago

The callbacks are set up so that you can do custom things at certain points during the process. If you're wanting to get the values of the hidden fields and do something with them at the callbackSuccess point in the plugin you could modify the callback with the additional parameters. In the processData method starting on line 1680 you could get the values:

var productID = $('#productID').val();

Then add the value to the callback:

// Callback
if (_this.settings.callbackSuccess) {
   _this.settings.callbackSuccess.call(this, productID);
}

However, you could accomplish that without modifying the plugin and updating the plugin call (the second code snippet you pasted above) with something like:

'callbackSuccess': function() {      
        var productID = $('#productID').val();
}

As far as I know you are not able to pass things back to the plugin with callbacks - they are just there to execute custom code at that point. It might help to have more details on what you are trying to do.