diff --git a/inc/field.class.php b/inc/field.class.php index 0257413d..95f249c2 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -995,6 +995,9 @@ function(obj, item) { {} ); + // Check current visibility state before refresh + const wasVisible = $('#{$html_id}').children().length > 0; + $.ajax( { url: '{$ajax_url}', @@ -1009,10 +1012,18 @@ function(obj, item) { input: data }, success: function(data) { - // Close open select2 dropdown that will be replaced - $('#{$html_id}').find('.select2-hidden-accessible').select2('close'); - // Refresh fields HTML - $('#{$html_id}').html(data); + // Check if visibility will change + const willBeVisible = data.trim() !== ''; + + // Only refresh if visibility state changes + // This prevents unnecessary DOM replacement that breaks validation event listeners + if (wasVisible !== willBeVisible) { + // Close open select2 dropdown that will be replaced + $('#{$html_id}').find('.select2-hidden-accessible').select2('close'); + + // Refresh fields HTML + $('#{$html_id}').html(data); + } } } );