var $region = $('#shipping_address_zone_id'); var $city = $('#shipping_address_city'); var $address = $("#shipping_address_address_1"); var $postal_code = $('#shipping_address_postcode'); var block_suggestion = ''; block_suggestion += '<div class="form-group">'; block_suggestion += ' <label for="suggestion_address"><strong>Поиск адреса и автозаполнение</strong></label>'; block_suggestion += ' <input id="suggestion_address" class="form-control" type="text" placeholder="Поиск адреса и автозаполнение">'; block_suggestion += '</div>'; function showRegion(address) { var findRegionValue = address.region.replace(/\s{0,1}[-\/].+/gi, '').toLowerCase(); if ($region.length) { $region.find('option').each(function (i, o) { if ($(o).text().toLowerCase().search(findRegionValue) >= 0) $(this).attr('selected', true); else $(this).attr('selected', false); }); } } function showCity(address) { if($city.length) { $city.val(join([address.city, address.settlement])); } } function showStreet(address) { if($address.length) { var addressValue = [ join([address.street_type, address.street, ], " "), join([address.house_type, address.house], " "), join([address.block_type, address.block], " "), join([address.flat_type, address.flat], " ") ]; $address.val(join(addressValue),); } } function showPostalCode(address) { if($postal_code.length) { $postal_code.val(address.postal_code); } } function showSelected(suggestion) { var address = suggestion.data; showPostalCode(address); showRegion(address); showCity(address); showStreet(address); setTimeout(function() { reloadAll(); }, 700); } function join(arr /*, separator */ ) { var separator = arguments.length > 1 ? arguments[1] : ", "; return arr.filter(function (n) { return n }).join(separator); } $('#simplecheckout_customer').after($(block_suggestion)); $("#suggestion_address").val( join([$city.val(), $address.val(), ], " "), ); $("#suggestion_address").suggestions({ token: 'Ваш токен', type: "ADDRESS", onSelect: showSelected });
Если у вас отличаются id полей, замените на свои
Это то что указано выше, пример:
var $region = $('#shipping_address_zone_id'); var $city = $('#shipping_address_city'); var $address = $("#shipping_address_address_1"); var $postal_code = $('#shipping_address_postcode');
Немає коментарів для відображення