diff --git a/src/registrar/assets/js/get-gov-admin.js b/src/registrar/assets/js/get-gov-admin.js index 9c75d9856..524cfe594 100644 --- a/src/registrar/assets/js/get-gov-admin.js +++ b/src/registrar/assets/js/get-gov-admin.js @@ -401,6 +401,30 @@ function initializeWidgetOnList(list, parentId) { sessionStorage.removeItem(name); } } + + document.addEventListener('DOMContentLoaded', function() { + let statusSelect = document.getElementById('id_status'); + + function moveStatusChangelog(actionNeededReasonFormGroup, statusSelect) { + let flexContainer = actionNeededReasonFormGroup.querySelector('.flex-container'); + let statusChangelog = document.getElementById('dja-status-changelog'); + if (statusSelect.value === "action needed") { + flexContainer.parentNode.insertBefore(statusChangelog, flexContainer.nextSibling); + } else { + // Move the changelog back to its original location + let statusFlexContainer = statusSelect.closest('.flex-container'); + statusFlexContainer.parentNode.insertBefore(statusChangelog, statusFlexContainer.nextSibling); + } + } + + // Call the function on page load + moveStatusChangelog(actionNeededReasonFormGroup, statusSelect); + + // Add event listener to handle changes to the selector itself + statusSelect.addEventListener('change', function() { + moveStatusChangelog(actionNeededReasonFormGroup, statusSelect); + }) + }); })(); /** An IIFE for toggling the submit bar on domain request forms