File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff 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 );
You can’t perform that action at this time.
0 commit comments