В настоящее время у меня есть следующая функция, которая выполняется, когда Ajax завершает работу на моей странице, которая затем загружается в тексте (на данный момент), а затем вызывает диалоговое окно автозаполнения.
<script type="text/javascript"> $(document).ajaxComplete(function() {
jQuery('#facetwp-location').val('Richmond, Vic'); // populate the input box
google.maps.event.trigger( document.querySelector('#facetwp-location'), 'focus', {} ); // force the autocomplete to show
});
</script>
Мне нужно сделать следующее:
- Получите информацию о местоположении пользователя из поля BuddyPress Xprofile (которое заменит заранее написанный текст)
- Автоматически загружать первый элемент в списке автозаполнения (т.е. имитировать нажатие клавиши и Enter в отображаемом списке.
Еще раз, мне не хватает навыков jQuery, и мне нужна небольшая помощь для выполнения этой функции.
Я работал над этим, и до сих пор у меня есть это - но он все еще не завершен
function get_user_location_for_facet_load(){
if (is_page(2101)) {
?>
<script type="text/javascript">
$(function() {
$(document).ajaxStop(function() {
jQuery('#facetwp-location').val('<?php
$user_id = bp_loggedin_user_id();
echo xprofile_get_field_data('Suburb',$user_id);
?>'); // populate the input box
$('#facetwp-location').focus();
google.maps.event.trigger( document.querySelector('#facetwp-location'), 'focus', {} ); // force the autocomplete to show
$( ".pac-container .pac-item:first" ).promise().done(function() {
google.maps.event.trigger( document.querySelector('.pac-container .pac-item'), 'focus', {} );
google.maps.event.trigger(document.querySelector('.pac-container .pac-item'), 'keydown', {
keyCode: 13
});
//var txt = $('#facetwp-location').val();
//alert(txt);
});
});
});
</script>
<?php
}
Не уверен, что я ближе, но может ли кто-нибудь помочь.