Skip to content

Commit df59be7

Browse files
authored
Fix - Prevent unnecessary container refresh breaking mandatory field validation (#1050)
1 parent 1bd5bf2 commit df59be7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

inc/field.class.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,9 @@ function(obj, item) {
995995
{}
996996
);
997997
998+
// Check current visibility state before refresh
999+
const wasVisible = $('#{$html_id}').children().length > 0;
1000+
9981001
$.ajax(
9991002
{
10001003
url: '{$ajax_url}',
@@ -1009,10 +1012,18 @@ function(obj, item) {
10091012
input: data
10101013
},
10111014
success: function(data) {
1012-
// Close open select2 dropdown that will be replaced
1013-
$('#{$html_id}').find('.select2-hidden-accessible').select2('close');
1014-
// Refresh fields HTML
1015-
$('#{$html_id}').html(data);
1015+
// Check if visibility will change
1016+
const willBeVisible = data.trim() !== '';
1017+
1018+
// Only refresh if visibility state changes
1019+
// This prevents unnecessary DOM replacement that breaks validation event listeners
1020+
if (wasVisible !== willBeVisible) {
1021+
// Close open select2 dropdown that will be replaced
1022+
$('#{$html_id}').find('.select2-hidden-accessible').select2('close');
1023+
1024+
// Refresh fields HTML
1025+
$('#{$html_id}').html(data);
1026+
}
10161027
}
10171028
}
10181029
);

0 commit comments

Comments
 (0)