- fixed select-type filters options;

This commit is contained in:
nikitasinelnikov
2019-11-21 11:41:52 +02:00
parent 76b06b26f6
commit 8859c48cdc
4 changed files with 39 additions and 24 deletions
+9 -10
View File
@@ -469,7 +469,6 @@ jQuery(document).ready(function() {
var me = jQuery(this);
var parent_option = me.data('um-parent');
var um_ajax_url = me.data('um-ajax-url');
var um_ajax_source = me.data('um-ajax-source');
var original_value = me.val();
@@ -480,7 +479,7 @@ jQuery(document).ready(function() {
var form_id = parent.closest('form').find('input[type="hidden"][name="form_id"]').val();
var arr_key = parent.val();
if ( parent.val() != '' && typeof um_select_options_cache[ arr_key ] != 'object' ) {
if ( arr_key != '' && typeof um_select_options_cache[ arr_key ] != 'object' ) {
jQuery.ajax({
url: wp.ajax.settings.url,
@@ -488,19 +487,19 @@ jQuery(document).ready(function() {
data: {
action: 'um_select_options',
parent_option_name: parent_option,
parent_option: parent.val(),
parent_option: arr_key,
child_callback: um_ajax_source,
child_name: me.attr('name'),
members_directory: me.attr('data-mebers-directory'),
child_name: me.attr('name'),
members_directory: me.attr('data-mebers-directory'),
form_id: form_id,
nonce: um_scripts.nonce
},
success: function( data ){
if( data.status == 'success' && parent.val() != '' ){
um_field_populate_child_options( me, data, arr_key);
if ( data.status == 'success' && arr_key != '' ) {
um_field_populate_child_options( me, data, arr_key );
}
if( typeof data.debug !== 'undefined' ){
if ( typeof data.debug !== 'undefined' ) {
console.log( data );
}
},
@@ -512,12 +511,12 @@ jQuery(document).ready(function() {
}
if ( parent.val() != '' && typeof um_select_options_cache[ arr_key ] == 'object' ) {
if ( 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 ( parent.val() == '' ){
if ( arr_key == '' ) {
me.find('option[value!=""]').remove();
me.val('').trigger('change');
}
+2 -4
View File
@@ -1150,15 +1150,13 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
* @return boolean
*/
public function skip_field_validation( $skip, $post_input, $array ) {
if ( $post_input === '_options' && isset( $array['post']['_custom_dropdown_options_source'] ) ) {
$um_callback_func = $array['post']['_custom_dropdown_options_source'];
$skip = function_exists( $um_callback_func );
$skip = function_exists( $array['post']['_custom_dropdown_options_source'] );
}
return $skip;
}
/**
* Retrieves dropdown/multi-select options from a callback function
+10 -6
View File
@@ -1124,11 +1124,14 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$arr_options = $opts['options'];
} elseif ( function_exists( $data['custom_dropdown_options_source'] ) ) {
if ( isset( $data['parent_dropdown_relationship'] ) ) {
$_POST['parent_option_name'] = $data['parent_dropdown_relationship'];
$_POST['parent_option'] = um_user( $data['parent_dropdown_relationship'] );
$arr_options = call_user_func(
$data['custom_dropdown_options_source'],
( ! empty( $data['parent_dropdown_relationship'] ) ? $data['parent_dropdown_relationship'] : '' )
);
$arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
} else {
$arr_options = call_user_func( $data['custom_dropdown_options_source'] );
}
}
if ( $has_custom_source || function_exists( $data['custom_dropdown_options_source'] ) ) {
@@ -2783,8 +2786,9 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
* }
* ?>
*/
$ajax_source_url = apply_filters( "um_custom_dropdown_options_source_url__{$form_key}", admin_url( 'admin-ajax.php' ), $data );
$atts_ajax .= ' data-um-ajax-url="' . esc_url( $ajax_source_url ) . '" ';
// todo maybe deprecate
// $ajax_source_url = apply_filters( "um_custom_dropdown_options_source_url__{$form_key}", admin_url( 'admin-ajax.php' ), $data );
// $atts_ajax .= ' data-um-ajax-url="' . esc_url( $ajax_source_url ) . '" ';
}
+18 -4
View File
@@ -524,11 +524,25 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
if ( ! empty( $attrs['custom_dropdown_options_source'] ) ) {
$attrs['custom'] = true;
$attrs['options'] = UM()->fields()->get_options_from_callback( $attrs, $attrs['type'] );
$custom_dropdown = ' data-um-ajax-source="' . esc_attr( $attrs['custom_dropdown_options_source'] ) . '"';
if ( ! empty( $attrs['parent_dropdown_relationship'] ) ) {
$custom_dropdown .= ' data-member-directory="yes"';
$custom_dropdown .= ' data-um-parent="' . esc_attr( $attrs['parent_dropdown_relationship'] ) . '"';
if ( isset( $_GET[ 'filter_' . $attrs['parent_dropdown_relationship'] . '_' . $unique_hash ] ) ) {
$_POST['parent_option_name'] = $attrs['parent_dropdown_relationship'];
$_POST['parent_option'] = explode( '||', filter_input( INPUT_GET, 'filter_' . $attrs['parent_dropdown_relationship'] . '_' . $unique_hash ) );
}
}
$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 ) . '" ';
}
if ( $attrs['metakey'] != 'role_select' ) {
if ( $attrs['metakey'] != 'role_select' && empty( $custom_dropdown ) ) {
$attrs['options'] = array_intersect( $attrs['options'], $values_array );
} elseif ( ! empty( $custom_dropdown ) ) {
$attrs['options'] = array_intersect_key( $attrs['options'], array_flip( $values_array ) );
} else {
$attrs['options'] = array_intersect_key( $attrs['options'], array_flip( $values_array ) );
}
@@ -545,7 +559,7 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
asort( $attrs['options'] ); ?>
<select class="um-s1" id="<?php echo $filter; ?>" name="<?php echo $filter; ?>"
<select class="um-s1" id="<?php echo esc_attr( $filter ); ?>" name="<?php echo esc_attr( $filter ); ?>"
data-placeholder="<?php esc_attr_e( stripslashes( $attrs['label'] ), 'ultimate-member' ); ?>"
<?php echo $custom_dropdown; ?>>
@@ -568,7 +582,7 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
<option value="<?php echo esc_attr( $opt ); ?>" data-value_label="<?php esc_attr_e( $v, 'ultimate-member' ); ?>"
<?php disabled( ! empty( $filter_from_url ) && in_array( $opt, $filter_from_url ) ) ?>
<?php selected( $opt == $default_value ) ?>>
<?php selected( $opt === $default_value ) ?>>
<?php _e( $v, 'ultimate-member' ); ?>
</option>