Aaron
Aaron

Reputation: 545

jQuery geocomplete output to custom fields

I have been trying to get it to map to fields i specify but have not had any luck. We have a form that we can not control the field names etc. and are trying to map the results to each field. Is it possible to map for say example the lat and long to fields that might be named like so

Lat input field name=ctl00$placeholderBody$ctl03$txtCustomField1

<input name="ctl00$placeholderBody$ctl03$txtCustomField1" type="text" id="ctl00_placeholderBody_ctl03_txtCustomField1">

Lon input field name=ctl00$placeholderBody$ctl03$txtCustomField2

<input name="ctl00$placeholderBody$ctl03$txtCustomField2" type="text" id="ctl00_placeholderBody_ctl03_txtCustomField2">

Here is an example but I do not see how to map the output to other custom field names. http://codepen.io/abennington/pen/dMgqRq

Any help and example code would be a life saver! :)

Upvotes: 0

Views: 478

Answers (1)

Leeish
Leeish

Reputation: 5213

$(document).ready(function(){
  // Call Geo Complete
  $('#ctl00_placeholderBody_ctl03_txtCustomField1').attr('data-geo','lat');
  $('#ctl00_placeholderBody_ctl03_txtCustomField2').attr('data-geo','lng');
  $("#search").geocomplete({details:"form#property",map:"#map",detailsAttribute:'data-geo'});
});

I got this to work. In your example you had the same ID names, but just add a attribute (whatever you want the plugin uses data-geo as an example), but add the attribute and then set the geocomplete to reference that attribute for the data. See the Populate form data section of the plugin.

Basically the plugin as you noticed is looking for fields names lat and lng. The detailsAttribute option tells the plugin to look for something other than the name attribute.

Upvotes: 1

Related Questions