- fixed callback select-type filters handlers on member directories filters bar;

This commit is contained in:
nikitasinelnikov
2019-11-21 18:41:47 +02:00
parent 2a0e018896
commit c0bc64b0ee
5 changed files with 73 additions and 26 deletions
+7 -10
View File
@@ -255,15 +255,6 @@ function um_ajax_get_members( directory, args ) {
if ( typeof value_to != 'undefined' ) {
var val_to = value_to.split(':');
var minutes = val_to[1]*1;
// var minutes = Math.ceil( val_to[1] ) + 1;
// if ( minutes >= 60 ) {
// minutes = 0;
// val_to[0] = val_to[0]*1 + 1;
//
// if ( val_to[0] >= 24 ) {
// val_to[0] = 0;
// }
// }
var hours = val_to[0]*1;
if ( hours < 10 ) {
@@ -949,6 +940,9 @@ jQuery(document.body).ready( function() {
directory.data( 'searched', 1 );
directory.find( '.um-member-directory-sorting-options' ).prop( 'disabled', false );
directory.find( '.um-member-directory-view-type' ).removeClass( 'um-disabled' );
// if ( directory.find( '.um-search-filter select[data-um-parent="' + filter_name + '"]' ).length > 0 ) {
// jQuery(this).trigger('change');
// }
});
@@ -1067,7 +1061,6 @@ jQuery(document.body).ready( function() {
um_set_url_from_data( directory, 'filter_' + filter_name, current_value );
var select = jQuery( '.um-search-filter select[name="' + filter_name + '"]' );
select.find('option[value="' + removeItem + '"]').prop('disabled', false).show();
@@ -1077,6 +1070,10 @@ jQuery(document.body).ready( function() {
}
select.select2('destroy').select2();
if ( directory.find( '.um-search-filter select[data-um-parent="' + filter_name + '"]' ).length > 0 ) {
select.trigger('change');
}
} else if ( type === 'slider' ) {
um_set_url_from_data( directory, 'filter_' + filter_name + '_from','' );
um_set_url_from_data( directory, 'filter_' + filter_name + '_to', '' );
+1 -1
View File
File diff suppressed because one or more lines are too long
+57 -13
View File
@@ -465,7 +465,7 @@ jQuery(document).ready(function() {
/**
* Find all select fields with parent select fields
*/
jQuery('select[data-um-parent]').each(function(){
jQuery('select[data-um-parent]').each( function() {
var me = jQuery(this);
var parent_option = me.data('um-parent');
@@ -474,12 +474,22 @@ jQuery(document).ready(function() {
me.attr('data-um-init-field', true );
jQuery(document).on('change','select[name="'+parent_option+'"]',function(){
jQuery(document).on('change','select[name="' + parent_option + '"]',function() {
var parent = jQuery(this);
var form_id = parent.closest('form').find('input[type="hidden"][name="form_id"]').val();
var arr_key = parent.val();
var form_id = parent.closest( 'form' ).find( 'input[type="hidden"][name="form_id"]' ).val();
if ( arr_key != '' && typeof um_select_options_cache[ arr_key ] != 'object' ) {
var arr_key;
if ( me.attr( 'data-member-directory' ) === 'yes' ) {
var directory = parent.parents('.um-directory');
arr_key = um_get_data_for_directory( directory, 'filter_' + parent_option );
if ( typeof arr_key != 'undefined' ) {
arr_key = arr_key.split('||');
}
} else {
arr_key = parent.val();
}
if ( typeof arr_key != 'undefined' && arr_key != '' && typeof um_select_options_cache[ arr_key ] != 'object' ) {
jQuery.ajax({
url: wp.ajax.settings.url,
@@ -490,7 +500,7 @@ jQuery(document).ready(function() {
parent_option: arr_key,
child_callback: um_ajax_source,
child_name: me.attr('name'),
members_directory: me.attr('data-mebers-directory'),
members_directory: me.attr('data-member-directory'),
form_id: form_id,
nonce: um_scripts.nonce
},
@@ -511,19 +521,19 @@ jQuery(document).ready(function() {
}
if ( arr_key != '' && typeof um_select_options_cache[ arr_key ] == 'object' ) {
if ( typeof arr_key != 'undefined' && arr_key != '' && typeof um_select_options_cache[ arr_key ] == 'object' ) {
var data = um_select_options_cache[ arr_key ];
um_field_populate_child_options( me, data, arr_key );
}
if ( arr_key == '' ) {
if ( typeof arr_key != 'undefined' || arr_key == '' ) {
me.find('option[value!=""]').remove();
me.val('').trigger('change');
}
});
jQuery('select[name="'+parent_option+'"]').trigger('change');
jQuery('select[name="' + parent_option + '"]').trigger('change');
});
@@ -534,6 +544,7 @@ jQuery(document).ready(function() {
* @param string key
*/
function um_field_populate_child_options( me, data, arr_key, arr_items ) {
var directory = me.parents('.um-directory');
var parent_option = me.data('um-parent');
var child_name = me.attr('name');
var parent_dom = jQuery('select[name="'+parent_option+'"]');
@@ -547,11 +558,10 @@ jQuery(document).ready(function() {
search_get = '';
if ( data.post.members_directory === 'yes' ) {
var urlParams = new URLSearchParams(window.location.search);
search_get = urlParams.get(data.post.child_name);
arr_items.push({id: '', text: '', selected: 1});
}
jQuery.each( data.items, function(k,v){
arr_items.push({id: k, text: v, selected: (v === search_get) });
arr_items.push({id: k, text: v, selected: (v === search_get)});
});
me.select2('destroy');
@@ -561,6 +571,41 @@ jQuery(document).ready(function() {
minimumResultsForSearch: 10
});
if ( data.post.members_directory === 'yes' ) {
me.find('option').each( function() {
if ( jQuery(this).html() !== '' ) {
jQuery(this).data( 'value_label', jQuery(this).html() ).attr( 'data-value_label', jQuery(this).html() );
}
});
var current_filter_val = um_get_data_for_directory( directory, 'filter_' + child_name );
if ( typeof current_filter_val != 'undefined' ) {
current_filter_val = current_filter_val.split('||');
var temp_filter_val = [];
jQuery.each( current_filter_val, function(i) {
if ( me.find('option[value="' + current_filter_val[ i ] + '"]').length ) {
temp_filter_val.push( current_filter_val[ i ] );
}
me.find('option[value="' + current_filter_val[ i ] + '"]').prop('disabled', true).hide();
if ( me.find('option:not(:disabled)').length === 1 ) {
me.prop('disabled', true);
}
me.select2('destroy').select2();
me.val('').trigger( 'change' );
});
temp_filter_val = temp_filter_val.join('||');
if ( current_filter_val !== temp_filter_val ) {
um_set_url_from_data( directory, 'filter_' + child_name, temp_filter_val );
um_ajax_get_members( directory );
}
}
um_change_tag( directory );
}
if ( data.post.members_directory !== 'yes' ) {
if ( typeof data.field.default !== 'undefined' && ! me.data('um-original-value') ) {
me.val( data.field.default ).trigger('change');
@@ -575,7 +620,6 @@ jQuery(document).ready(function() {
}
um_select_options_cache[ arr_key ] = data;
}
});
+1 -1
View File
File diff suppressed because one or more lines are too long
+7 -1
View File
@@ -523,9 +523,9 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
$custom_dropdown = '';
if ( ! empty( $attrs['custom_dropdown_options_source'] ) ) {
$attrs['custom'] = true;
$attrs['options'] = UM()->fields()->get_options_from_callback( $attrs, $attrs['type'] );
if ( ! empty( $attrs['parent_dropdown_relationship'] ) ) {
$custom_dropdown .= ' data-member-directory="yes"';
$custom_dropdown .= ' data-um-parent="' . esc_attr( $attrs['parent_dropdown_relationship'] ) . '"';
@@ -537,6 +537,8 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
$ajax_source = apply_filters( "um_custom_dropdown_options_source__{$filter}", $attrs['custom_dropdown_options_source'], $attrs );
$custom_dropdown .= ' data-um-ajax-source="' . esc_attr( $ajax_source ) . '" ';
$attrs['options'] = UM()->fields()->get_options_from_callback( $attrs, $attrs['type'] );
}
if ( $attrs['metakey'] != 'role_select' && empty( $custom_dropdown ) ) {
@@ -553,6 +555,10 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
return '';
}
if ( ! empty( $attrs['custom_dropdown_options_source'] ) && ! empty( $attrs['parent_dropdown_relationship'] ) ) {
$attrs['options'] = array();
}
if ( isset( $attrs['label'] ) ) {
$attrs['label'] = strip_tags( $attrs['label'] );
}