Skip to content

Commit

Permalink
Merge pull request #2239 from iamibrahimriaz/improve/radius-search
Browse files Browse the repository at this point in the history
Radius Search Range Issue - Fixed
  • Loading branch information
Armanul46 authored Feb 25, 2025
2 parents 332b8e7 + ec9e9e2 commit 90924da
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 28 deletions.
21 changes: 19 additions & 2 deletions assets/js/all-listings.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/js/range-slider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions assets/js/search-form.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions assets/src/js/public/components/instantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ import debounce from '../../global/components/debounce';
if (form_data.phone && form_data.phone.length) {
var query = (query && query.length) ? query + '&phone=' + form_data.phone : '?phone=' + form_data.phone;
}
if (form_data.custom_field && form_data.custom_field.length) {
var query = (query && query.length) ? query + '&custom_field=' + form_data.custom_field : '?custom_field=' + form_data.custom_field;
if (form_data.custom_field && Object.keys(form_data.custom_field).length) {
Object.keys(form_data.custom_field).forEach((key) => {
query = (query.length) ? query + `&${key}=${form_data.custom_field[key]}` : `?${key}=${form_data.custom_field[key]}`;
});
}
if (form_data.open_now && form_data.open_now.length) {
var query = (query && query.length) ? query + '&open_now=' + form_data.open_now : '?open_now=' + form_data.open_now;
Expand Down Expand Up @@ -1458,6 +1460,24 @@ import debounce from '../../global/components/debounce';
filterListing(searchElm);
}, 250));

// sidebar on change location, zipcode changing
$('body').on("change", ".directorist-instant-search .listing-with-sidebar .directorist-search-location, .directorist-instant-search .listing-with-sidebar .directorist-zipcode-search", debounce(function (e) {
e.preventDefault();

const searchElm = $(this).closest('.listing-with-sidebar');

// If it's a location field, ensure it has a value before triggering the filter
if ($(this).hasClass('directorist-search-location')) {
const locationField = $(this).find('input[name="address"]');
if (!locationField.val()) {
return;
}
}

filterListing(searchElm);
}, 250));


// select on change with value - searching
$('body').on("change", ".directorist-instant-search .listing-with-sidebar select", debounce( function(e) {
e.preventDefault();
Expand Down
33 changes: 26 additions & 7 deletions assets/src/js/public/search-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,11 @@ import './components/directoristSelect';
$('.directorist-location-js, .atbdp-search-address').attr("data-value", data.display_name);
$('#cityLat').val(lat);
$('#cityLng').val(lng);

const locationSearch = $(".directorist-search-location");
if (locationSearch.length) {
locationSearch.trigger("change");
}
}
});
}
Expand All @@ -922,7 +927,9 @@ import './components/directoristSelect';

locationAddressField.removeClass('atbdp-form-fade');

$('body').on("click", '.address_result .current-location', function (e) {
$('body').off("click", '.address_result .current-location').on("click", '.address_result .current-location', function (e) {
e.preventDefault();

navigator.geolocation.getCurrentPosition(function (position) {
return displayLocation(position, e);
});
Expand All @@ -941,7 +948,17 @@ import './components/directoristSelect';

// hide address result when click outside the input field
$(document).on('click', function (e) {
if (!$(e.target).closest('.directorist-location-js, #q_addressss, .atbdp-search-address').length) {
if (!$(e.target).closest('.directorist-location-js, #q_addressss, .atbdp-search-address, .current-location').length) {
const locationSearch = $(e.target).closest(".directorist-search-location");
const zipCodeSearch = $(e.target).closest(".directorist-zipcode-search");

if (locationSearch.length) {
locationSearch.trigger("change");
}
if (zipCodeSearch.length) {
zipCodeSearch.trigger("change");
}

$('.address_result').hide();
}
});
Expand Down Expand Up @@ -1005,8 +1022,9 @@ import './components/directoristSelect';
if (!slider || slider.directoristCustomRangeSlider) return;

let sliderStep = parseInt(slider.getAttribute('step')) || 1;
let sliderDefaultValue = parseInt(slider.getAttribute('value') || 0);
let sliderMaxValue = parseInt(slider.getAttribute('max-value') || 100);
let sliderMinValue = parseInt(slider.getAttribute('min-value'));
let sliderMaxValue = parseInt(slider.getAttribute('max-value'));
let sliderDefaultValue = parseInt(slider.getAttribute('default-value'));
let minInput = sliderItem.querySelector('.directorist-custom-range-slider__value__min');
let maxInput = sliderItem.querySelector('.directorist-custom-range-slider__value__max');
let sliderRange = sliderItem.querySelector('.directorist-custom-range-slider__range');
Expand All @@ -1018,15 +1036,16 @@ import './components/directoristSelect';
let rangeInitLoad = true;
// Parse the URL parameters
const milesParams = new URLSearchParams(window.location.search).has('miles');
const customParams = new URLSearchParams(window.location.search).has('miles');

directoristCustomRangeSlider?.create(slider, {
start: [0, sliderDefaultValue ? sliderDefaultValue : 100],
start: [minInput.value, milesParams || customParams ? maxInput.value : sliderDefaultValue || sliderMaxValue],
connect: true,
direction: isRTL ? 'rtl' : 'ltr',
step: sliderStep ? sliderStep : 1,
range: {
'min': Number(minInput.value ? minInput.value : 0),
'max': Number(maxInput.value ? maxInput.value : 100)
'min': Number(sliderMinValue || 0),
'max': Number(sliderMaxValue || 100)
}
});

Expand Down
14 changes: 10 additions & 4 deletions templates/search-form/custom-fields/number/range.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,32 @@

if ( ! defined( 'ABSPATH' ) ) exit;

$min_val = $data['options']['min_value'] ?? 1;
$min_value = $data['options']['min_value'] ?? 1;
$max_value = $data['options']['max_value'] ?? 100;
$default_min_value = $data['options']['min_value'] ?? 1;
$default_max_value = $data['options']['max_value'] ?? 100;

if (!empty($value) && strpos($value, '-') !== false) {
list($min_value, $max_value) = explode('-', $value);
}
?>

<div class="directorist-search-field directorist-search-field-text_range">
<?php if ( !empty($data['label']) ): ?>
<label><?php echo esc_html( $data['label'] ); ?></label>
<?php endif; ?>
<div class="directorist-custom-range-slider">
<div class="directorist-custom-range-slider__slide" step="<?php echo esc_attr( ! empty( $data['options']['step'] ) ? absint( $data['options']['step'] ) : 1 ); ?>" aria-label="Range" max-value="<?php echo esc_attr($max_value); ?>"></div>
<div class="directorist-custom-range-slider__slide" step="<?php echo esc_attr( ! empty( $data['options']['step'] ) ? absint( $data['options']['step'] ) : 1 ); ?>" aria-label="Range" min-value="<?php echo esc_attr($default_min_value); ?>" max-value="<?php echo esc_attr($default_max_value); ?>"></div>
<div class="directorist-custom-range-slider__wrap">
<div class="directorist-custom-range-slider__value">
<label for="directorist-custom-range-slider__value__min__number" class="directorist-custom-range-slider__label"><?php esc_html_e( 'Min', 'directorist' ); ?></label>
<input type="number" placeholder="Min" value="<?php echo esc_attr( $min_val ) ?>" name="directorist-custom-range-slider__value__min" id="directorist-custom-range-slider__value__min__number" class="directorist-custom-range-slider__text directorist-custom-range-slider__value__min">
<input type="number" placeholder="Min" value="<?php echo esc_attr( $min_value ) ?>" name="directorist-custom-range-slider__value__min" id="directorist-custom-range-slider__value__min__number" class="directorist-custom-range-slider__text directorist-custom-range-slider__value__min">
</div>
<div class="directorist-custom-range-slider__value">
<label for="directorist-custom-range-slider__value__max__number" class="directorist-custom-range-slider__label"><?php esc_html_e( 'Max', 'directorist' ); ?></label>
<input type="number" placeholder="Max" value="<?php echo esc_attr( $max_value ) ?>" name="directorist-custom-range-slider__value__max" id="directorist-custom-range-slider__text directorist-custom-range-slider__value__max__number" class="directorist-custom-range-slider__value__max">
</div>
<input type="hidden" name="custom_field[<?php echo esc_attr( $data['field_key'] ); ?>]" class="directorist-custom-range-slider__range" value="<?php echo esc_attr( $min_val ) ?>-<?php echo esc_attr( $max_value ) ?>">
<input type="hidden" name="custom_field[<?php echo esc_attr( $data['field_key'] ); ?>]" class="directorist-custom-range-slider__range" value="<?php echo esc_attr( $min_value ) ?>-<?php echo esc_attr( $max_value ) ?>">
</div>
</div>

Expand Down
12 changes: 7 additions & 5 deletions templates/search-form/fields/radius_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

if (!defined('ABSPATH')) exit;

$min_distance = '0';
$default_distance = $data['default_radius_distance'] ?? 0;
$max_distance = $data['max_radius_distance'] ?? 1000;
$value = ! empty( $_REQUEST['miles'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['miles'] ) ) : $min_distance . '-' . $max_distance;
$min_distance = 0;
$default_min_distance = 0;
$max_distance = $data['max_radius_distance'] ?? 0;
$default_max_distance = $data['max_radius_distance'] ?? 100;
$default_distance = $data['default_radius_distance'] ?? 50;
$value = ! empty( $_REQUEST['miles'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['miles'] ) ) : $min_distance . '-' . $max_distance;

if ( ! empty( $_REQUEST['miles'] ) ) {
$distance = directorist_get_distance_range( $_REQUEST['miles'] );
Expand All @@ -28,7 +30,7 @@
<span class="directorist-custom-range-slider__range__show"></span>
<span><?php echo esc_attr($searchform->range_slider_unit($data)); ?></span>
</div>
<div class="directorist-custom-range-slider__slide" value="<?php echo esc_attr($default_distance); ?>" max-value="<?php echo esc_attr($max_distance); ?>"></div>
<div class="directorist-custom-range-slider__slide" default-value="<?php echo esc_attr($default_distance); ?>" max-value="<?php echo esc_attr($default_max_distance); ?>" min-value="<?php echo esc_attr($default_min_distance); ?>"></div>
<div class="directorist-custom-range-slider__wrap">
<input type="hidden" placeholder="Min" value="<?php echo esc_attr($min_distance); ?>" class="directorist-custom-range-slider__radius directorist-custom-range-slider__value__min">
<input type="hidden" placeholder="Max" value="<?php echo esc_attr($max_distance); ?>" class="directorist-custom-range-slider__radius directorist-custom-range-slider__value__max">
Expand Down

0 comments on commit 90924da

Please sign in to comment.