Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ function(obj, item) {
{}
);

// Check current visibility state before refresh
const wasVisible = $('#{$html_id}').children().length > 0;

$.ajax(
{
url: '{$ajax_url}',
Expand All @@ -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);
}
}
}
);
Expand Down