diff --git a/assets/js/um-conditional.js b/assets/js/um-conditional.js index c66433d3..e6af4784 100644 --- a/assets/js/um-conditional.js +++ b/assets/js/um-conditional.js @@ -12,7 +12,6 @@ jQuery(document).ready( function (){ function um_get_field_default_value( $dom ) { var default_value = ''; var type = um_get_field_type($dom); - switch ( type ) { case 'text': @@ -25,7 +24,6 @@ jQuery(document).ready( function (){ case 'multiselect': default_value = $dom.find('select').val(); - break; case 'radio': @@ -249,7 +247,6 @@ jQuery(document).ready( function (){ } if (condition.operator == 'equals to') { - if (condition.value == live_field_value && um_in_array(live_field_value, $owners_values[condition.owner])) { $owners[condition.owner][index] = true; } else { @@ -515,6 +512,11 @@ jQuery(document).ready( function (){ um_apply_conditions(me, false); }); + jQuery(document).on('input change', '.um-field input[type=number]', function () { + var me = jQuery(this); + um_apply_conditions(me, false); + }); + jQuery(document).on('input change', '.um-field input[type=password]', function () { var me = jQuery(this); um_apply_conditions(me, false); diff --git a/includes/admin/assets/js/um-admin-field.js b/includes/admin/assets/js/um-admin-field.js index 035f4714..87866a1e 100644 --- a/includes/admin/assets/js/um-admin-field.js +++ b/includes/admin/assets/js/um-admin-field.js @@ -1,5 +1,26 @@ jQuery(document).ready(function() { + /* Remove deleted condition fields */ + jQuery(document).on('click', '.um-admin-btn-toggle a', function(){ + var fields = jQuery('.um-admin-btn-content').find('[name*="_conditional_field"]'); + + jQuery.each(fields, function(index, value) { + if ( !jQuery(value).val() ) { + console.log(jQuery(value).parents('.um-admin-cur-condition').find('.um-admin-remove-condition')); + jQuery(value).parents('.um-admin-cur-condition').remove(); + } + }); + + var form = jQuery('form.um_add_field'); + + jQuery.ajax({ + url: um_admin_field_data.ajax_url, + type: 'POST', + dataType: 'json', + data: form.serialize() + }); + }); + /* Remove field permanently */ jQuery(document).on('click', '.um-admin-btns a span.remove', function(e){ e.preventDefault(); @@ -35,8 +56,6 @@ jQuery(document).ready(function() { var form = jQuery(this); - console.log(um_admin_field_data.ajax_url); - jQuery.ajax({ url: um_admin_field_data.ajax_url, type: 'POST', @@ -52,35 +71,34 @@ jQuery(document).ready(function() { form.css({'opacity': 1}); }, success: function(data){ - console.log(data); - // if (data.error){ - // - // c = 0; - // jQuery.each(data.error, function(i, v){ - // c++; - // if ( c == 1 ) { - // form.find('#'+i).addClass('um-admin-error').focus(); - // form.find('.um-admin-error-block').show().html(v); - // } - // }); - // - // um_admin_modal_responsive(); - // - // } else { - // - // jQuery('.um-col-demon-settings').data('in_row', ''); - // jQuery('.um-col-demon-settings').data('in_sub_row', ''); - // jQuery('.um-col-demon-settings').data('in_column', ''); - // jQuery('.um-col-demon-settings').data('in_group', ''); - // - // um_admin_remove_modal(); - // um_admin_update_builder(); - // - // } + if (data.error){ + + c = 0; + jQuery.each(data.error, function(i, v){ + c++; + if ( c == 1 ) { + form.find('#'+i).addClass('um-admin-error').focus(); + form.find('.um-admin-error-block').show().html(v); + } + }); + + um_admin_modal_responsive(); + + } else { + + jQuery('.um-col-demon-settings').data('in_row', ''); + jQuery('.um-col-demon-settings').data('in_sub_row', ''); + jQuery('.um-col-demon-settings').data('in_column', ''); + jQuery('.um-col-demon-settings').data('in_group', ''); + + um_admin_remove_modal(); + um_admin_update_builder(); + + } }, error: function(data){ - console.log(data); + } }); diff --git a/includes/core/class-enqueue.php b/includes/core/class-enqueue.php index b723b213..e801c8c1 100644 --- a/includes/core/class-enqueue.php +++ b/includes/core/class-enqueue.php @@ -329,7 +329,7 @@ if ( ! class_exists( 'um\core\Enqueue' ) ) { */ function load_customjs() { - wp_register_script('um_conditional', um_url . 'assets/js/um-conditional' . $this->suffix . '.js' ); + wp_register_script('um_conditional', um_url . 'assets/js/um-conditional.js' ); wp_enqueue_script('um_conditional'); wp_register_script('um_scripts', um_url . 'assets/js/um-scripts' . $this->suffix . '.js' );